Wluper Plugin

Getting Started

  1. Add the package in dev_dependencies.
dev_dependencies:
  wluper_plugin_flutter: ^1.1.0
  1. Import the plugin in main.dart or where you need.
import 'package:wluper_plugin_flutter/wluper_plugin_flutter.dart';
import 'package:wluper_plugin_flutter/wluper_plugin_interface.dart';
  1. Implement WluperPluginInterface protocol in the class where you want manipulate the parsed tree.
class _MyAppState extends State<MyApp> implements WluperPluginInterface {
    ...
  1. Override the methods of the WluperPluginInterface to handle Errors, live text and end of speech event.
  @override
  void wluperOnError(String error){
 		// implement here your code
  }

  @override
  void wluperOnLiveText(String text){
		// implement here your code
  }

  @override
  void wluperEndOfSpeech(){
		// implement here your code
  }
  1. Declare WluperPluginFlutter object.
class _MyAppState extends State<MyApp> implements WluperPluginInterface {
    ...
    WluperPluginFlutter wluperSDK = WluperPluginFlutter();
    ...
  1. Initialise the SDK with the tu_api_key, log_api_key, client_id and the WluperPluginInterface listener.
Future<void> initPlatformState() async {
    ...
      wluperSDK.init(this, _client_id, _tu_api_key, _log_api_key ).then((result) => /*implement here your code*/ );
    ...
  1. Wrap plugin methods wluperSDK.startListening(), wluperSDK.understand() and wluperSDK.understand().
class _MyAppState extends State<MyApp> implements WluperPluginInterface {
    ...

  void startListening(){
    wluperSDK.startListening().then((result) => /*implement here your code*/);
  }

  void understand(text){
    wluperSDK.understand(text).then((result) => /*implement here your code*/);
  }

  void cancelListening(){
  	wluperSDK.cancelListening().then((result) => setState(() => /*implement here your code*/);
  }

    ...
  1. Invoke the methods startListening(), understand(text) and cancelListening() from UI. While you speak, the live text is received by the listener wluperOnLiveText . The end of speech is detected automatically by the SDK and it is notified in the wluperEndOfSpeech callback (see point 4).
class _MyAppState extends State<MyApp> implements WluperPluginInterface{
  String _status = 'Unknown';
  String _tree = "";
  String _error = "";
  String _plain_text ="";
...
  void cleanUI(){
      setState(() {
        _status = "";
        _error= "";
        _tree = "";
        _plain_text = "";
      });
  }
...
	children: <Widget>[
    Text('SDK STATUS', style: TextStyle(fontWeight: FontWeight.bold)),
    Text(_status),
    Row(
      children: <Widget>[
        TextButton(style: TextButton.styleFrom( textStyle: const TextStyle(fontSize: 20)),
                   onPressed: () { cleanUI(); startListening(); },
                   child: const Text('Listen')),
        TextButton( style: TextButton.styleFrom(textStyle: const TextStyle(fontSize: 20)),
                   onPressed: () { cancelListening();},
                   child: const Text('Cancel'))
      ],
    ),
    Text('ASR OUTPUT', style: TextStyle(fontWeight: FontWeight.bold)),
    TextField( controller: textController,
              maxLines: 3,
              decoration: const InputDecoration( border: OutlineInputBorder(),
                                  hintText: 'Enter a sentence to understand')),
    TextButton( style: TextButton.styleFrom( textStyle: const TextStyle(fontSize: 20)),
               onPressed: () { understand(textController.text); },
               child: const Text('Understand')),
    Text('BODY RESPONSE', style: TextStyle(fontWeight: FontWeight.bold)),
    Text(_tree),
    Text('ERROR', style: TextStyle(fontWeight: FontWeight.bold)),
    Text(_error),
  ])
...
  1. Permissions

Android Add below permission to the AndroidManifest.xml

<uses-permission android:name="android.permission.RECORD_AUDIO" />

iOS Add below permissions to info.plist

<key>NSMicrophoneUsageDescription</key>
<string>Audio is recorded and transcribed.</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>We need to record your voice.</string>