我想说:
“我的账户余额是多少”
将上述语音转换为数组的简单示例;
words = {
[What]
[is]
[my]
[Account]
[Balance]
};
所以,我可以检查单词并路由到相应的页面。
switch (voiceToRoute) {
case “Account”:
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new AccountPage()));
},
break;
case “Balance”:
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new BalancePage()));
},
break;
}
有人可以在 Dart/Flutter 中提供关于语音转文本的解决方案吗?
有一个语音识别库可能适合您的需求: https://pub.dartlang.org/packages/speech_recognition
查看这个将语音转换为文本的 API。您可以使用以下代码在 flutter 应用程序中实现。
import 'package:http/http.dart' as http;
void main() async {
final url = Uri.parse('https://api.apyhub.com/stt/file');
final req = http.MultipartRequest('POST', url)
..files.add(await http.MultipartFile.fromPath(
'file', 'sample.wav'))
..fields['language'] = 'en-US';
req.headers['apy-token'] = 'SECRET-APY-TOKEN';
req.headers['content-type'] = 'multipart/form-data';
final stream = await req.send();
final res = await http.Response.fromStream(stream);
final status = res.statusCode;
if (status != 200) throw Exception('http.send error: statusCode= $status');
print(res.body);
}
您可以从
这里生成
secret-apy-token
(它是免费的,并在入门计划中提供高达2M的API调用)