Wluper Plugin
Getting Started
- Add the package in
dev_dependencies.
dev_dependencies:
wluper_plugin_flutter: ^1.1.0
- Import the plugin in
main.dartor where you need.
import 'package:wluper_plugin_flutter/wluper_plugin_flutter.dart';
import 'package:wluper_plugin_flutter/wluper_plugin_interface.dart';
- Implement
WluperPluginInterfaceprotocol in the class where you want manipulate the parsed tree.
class _MyAppState extends State<MyApp> implements WluperPluginInterface {
...
- Override the methods of the
WluperPluginInterfaceto 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
}
- Declare
WluperPluginFlutterobject.
class _MyAppState extends State<MyApp> implements WluperPluginInterface {
...
WluperPluginFlutter wluperSDK = WluperPluginFlutter();
...
- Initialise the SDK with the
tu_api_key,log_api_key,client_idand theWluperPluginInterfacelistener.
Future<void> initPlatformState() async {
...
wluperSDK.init(this, _client_id, _tu_api_key, _log_api_key ).then((result) => /*implement here your code*/ );
...
- Wrap plugin methods
wluperSDK.startListening(),wluperSDK.understand()andwluperSDK.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*/);
}
...
- Invoke the methods
startListening(),understand(text)andcancelListening()from UI. While you speak, the live text is received by the listenerwluperOnLiveText. The end of speech is detected automatically by the SDK and it is notified in thewluperEndOfSpeechcallback (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),
])
...
- 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>