Android 在我的Flitter应用程序中,这个语音识别错误意味着什么?
我的Flitter应用程序有一个错误,所以基本上我制作了一个语音到文本的应用程序,它可以在我的iOS模拟器和设备上完美地工作。但在我的android emulator上,当我启动speech to text函数时,它会输出以下错误:Android 在我的Flitter应用程序中,这个语音识别错误意味着什么?,android,flutter,gradle,speech-recognition,speech-to-text,Android,Flutter,Gradle,Speech Recognition,Speech To Text,我的Flitter应用程序有一个错误,所以基本上我制作了一个语音到文本的应用程序,它可以在我的iOS模拟器和设备上完美地工作。但在我的android emulator上,当我启动speech to text函数时,它会输出以下错误: I/flutter ( 4958): onError: SpeechRecognitionError msg: error_permission, permanent: true 我也在使用这个演讲文本包: speech_to_text: ^2.3.0 有人知道
I/flutter ( 4958): onError: SpeechRecognitionError msg: error_permission, permanent: true
我也在使用这个演讲文本包:
speech_to_text: ^2.3.0
有人知道这是什么意思吗?我还在AndroidManifest.xml中添加了需求,“录制音频”和“互联网”需求。(这些已列在此包的pub.dev页面上)
这是我的密码:
class SpeechScreen extends StatefulWidget {
@override
_SpeechScreenState createState() => _SpeechScreenState();
}
class _SpeechScreenState extends State<SpeechScreen> {
final Map<String, HighlightedWord> _highlights = {
'Hablas': HighlightedWord(
onTap: () => print('voice'),
textStyle: const TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
),
),
};
stt.SpeechToText _speech;
bool _isListening = false;
String _text = 'Press the button and start speaking';
double _confidence = 1.0;
@override
void initState() {
super.initState();
_speech = stt.SpeechToText();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Speech To Text'),
centerTitle: true,
backgroundColor: Colors.orange,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: AvatarGlow(
animate: _isListening,
glowColor: Colors.red,
endRadius: 75.0,
duration: const Duration(milliseconds: 2000),
repeatPauseDuration: const Duration(milliseconds: 100),
repeat: true,
child: RawMaterialButton(
onPressed: _listen,
child: Icon(
_isListening ? Icons.mic : Icons.mic_none,
size: 32,
color: Colors.white,
),
fillColor: Colors.red,
elevation: 2.0,
padding: EdgeInsets.all(15.0),
shape: CircleBorder(),
constraints: BoxConstraints.tight(Size(64, 64)),
splashColor: Colors.red),
),
body: SingleChildScrollView(
reverse: true,
child: Container(
padding: const EdgeInsets.fromLTRB(30.0, 30.0, 30.0, 150.0),
width: double.infinity,
child: Column(
children: [
Text(
'AI Confidence Level: ${(_confidence * 100.0).toStringAsFixed(1)}%',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 32.0,
color: Colors.black,
fontWeight: FontWeight.w700,
),
),
SizedBox(
height: 50,
),
TextHighlight(
text: _text,
words: _highlights,
textAlign: TextAlign.center,
textStyle: const TextStyle(
fontSize: 32.0,
color: Colors.black,
fontWeight: FontWeight.w400),
),
],
)),
),
);
}
void _listen() async {
if (!_isListening) {
bool available = await _speech.initialize(
onStatus: (val) => print('onStatus: $val'),
onError: (val) => print('onError: $val'),
);
if (available) {
setState(() => _isListening = true);
_speech.listen(
onResult: (val) => setState(() {
_text = val.recognizedWords;
if (val.hasConfidenceRating && val.confidence > 0) {
_confidence = val.confidence;
}
}),
);
}
} else {
setState(() => _isListening = false);
_speech.stop();
}
}
}
class SpeechScreen扩展StatefulWidget{
@凌驾
_SpeechScreenState createState()=>_SpeechScreenState();
}
类_SpeechScreenState扩展状态{
最终地图_亮点={
“哈布拉斯”:突出的单词(
onTap:()=>打印('voice'),
textStyle:const textStyle(
颜色:颜色。绿色,
fontWeight:fontWeight.bold,
),
),
};
stt.SpeechToText\u演讲;
bool_isListening=false;
String _text='按下按钮开始说话';
双置信度=1.0;
@凌驾
void initState(){
super.initState();
_speech=stt.SpeechToText();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“演讲到文本”),
标题:对,
背景颜色:Colors.orange,
),
浮动ActionButtonLocation:浮动ActionButtonLocation.centerFloat,
浮动操作按钮:AvatarGlow(
动画:_正在播放,
glowColor:Colors.red,
端半径:75.0,
持续时间:常量持续时间(毫秒:2000),
repeatPauseDuration:常量持续时间(毫秒:100),
重复:对,
子项:RawMaterialButton(
按:听着,
子:图标(
_isListening?Icons.mic:Icons.mic\u无,
尺码:32,
颜色:颜色,白色,
),
fillColor:Colors.red,
标高:2.0,
填充:所有边缘设置(15.0),
形状:CircleBorder(),
约束:BoxConstraints.tight(大小(64,64)),
颜色:颜色。红色),
),
正文:SingleChildScrollView(
相反:是的,
子:容器(
填充:LTRB(30.0,30.0,30.0,150.0)中的常数边集,
宽度:double.infinity,
子:列(
儿童:[
正文(
'AI置信水平:${(_-Confidence*100.0).toStringAsFixed(1)}%',
textAlign:textAlign.center,
样式:TextStyle(
字体大小:32.0,
颜色:颜色,黑色,
fontWeight:fontWeight.w700,
),
),
大小盒子(
身高:50,
),
文本突出显示(
文本:_text,
关键词:"重点,,
textAlign:textAlign.center,
textStyle:const textStyle(
字体大小:32.0,
颜色:颜色,黑色,
fontWeight:fontWeight.w400),
),
],
)),
),
);
}
void\u listen()异步{
如果(!\u正在列表){
bool available=wait\u speech.initialize(
onStatus:(val)=>print('onStatus:$val'),
onError:(val)=>print('onError:$val'),
);
如果有(可用){
设置状态(()=>\u isListening=true);
_演讲,听(
onResult:(val)=>setState(){
_text=val.recognizedWords;
如果(val.hasConference&&val.Conference>0){
_信心=价值信心;
}
}),
);
}
}否则{
设置状态(()=>\u isListening=false);
_演讲。停止();
}
}
}
它在android上不工作,因为您没有授予它录制音频的权限。导航到此文件:
<project root>/android/app/src/main/AndroidManifest.xml
/android/app/src/main/AndroidManifest.xml
再加上这两行
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.INTERNET"/>
最后应该是这样的:
是的,我做到了。。。似乎仍然不起作用。你有什么错误?还是一样吗?如果是,你能把你的清单文件寄给我吗?PS:确保您将其写入了主文件夹中的清单文件,而不是调试文件夹中。否则就不行了。是的,当然,介意我在不和谐的时候发吗?不,只要发就行了:)