I have an error with my flutter app, so basically I have made a speech to text app, and it works on my iOS simulator and device perfectly. But on my android emulator, when I start the speech to text function, it outputs this error:
I/flutter ( 4958): onError: SpeechRecognitionError msg: error_permission, permanent: true
I am also using this speech to text package:
speech_to_text: ^2.3.0
Does anyone know what this means? I have also added the requirements in the AndroidManifest.xml, the "RECORD_AUDIO" and "INTERNET" ones. (these were listed on the pub.dev page for this package)
Here is my code:
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();
}
}
}
