This commit is contained in:
hh
2022-01-24 16:10:41 +08:00
commit e33c5a9737
69 changed files with 2056 additions and 0 deletions

View File

@ -0,0 +1,64 @@
import 'dart:async';
import 'package:flutter/services.dart';
typedef Future<dynamic> EventHandler(Map<String, dynamic> event);
class IflytekSpeechDemo {
static const MethodChannel _channel = MethodChannel('iflytek_speech_demo');
late EventHandler _onReceiveSpeechText;
// test方法
static Future<String?> get platformVersion async {
final String? version = await _channel.invokeMethod('getPlatformVersion');
return version;
}
// 编写自定义异步方法调用原生sdk传递过来的数据
// 1. 初始化方法
Future<int> init(String appId) async {
try{
int ret = await _channel.invokeMethod('init', {
"appID": appId
});
if(ret == 0) {
_channel.setMethodCallHandler(_handleMethod);
}
return ret;
}catch(e) {
print(e);
return 9999999;
}
}
Future<Future> _handleMethod(MethodCall call) async {
print("speech_handleMethod:");
switch (call.method) {
case "onReceiveSpeechText":
return _onReceiveSpeechText(call.arguments.cast<String, dynamic>());
default:
throw UnsupportedError("Unrecognized Event:"+call.method);
}
}
Future<String> start(EventHandler onReceiveSpeechText) async {
_onReceiveSpeechText = onReceiveSpeechText;
try{
return await _channel.invokeMethod('start');
}catch(e) {
print(e);
return "9999999";
}
}
Future<String> stop() async {
return await _channel.invokeMethod('stop');
}
Future<String> cancel() async {
return await _channel.invokeMethod('cancel');
}
}