gpt4 book ai didi

android - 这个语音识别错误在我的 flutter 应用程序中意味着什么?

转载 作者:行者123 更新时间:2023-12-05 00:03:01 31 4
gpt4 key购买 nike

我的 flutter 应用程序出现错误,所以基本上我已经对文本应用程序进行了演讲,它可以在我的 iOS 模拟器和设备上完美运行。但是在我的 android 模拟器上,当我启动语音转文本功能时,它会输出此错误:

I/flutter ( 4958): onError: SpeechRecognitionError msg: error_permission, permanent: true
我也在使用这个语音到文本包:
speech_to_text: ^2.3.0
有谁知道这意味着什么?我还在 AndroidManifest.xml、“RECORD_AUDIO”和“INTERNET”中添加了要求。 (这些都列在这个包的 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();
}
}
}

最佳答案

它不适用于android,因为您没有授予它录制音频的权限。导航到此文件:

<project root>/android/app/src/main/AndroidManifest.xml
并将这两行添加到它
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.INTERNET"/>
最后它应该看起来像这样:
enter image description here

关于android - 这个语音识别错误在我的 flutter 应用程序中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67725879/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com