I'm using speech_to_text: ^5.6.1
plugin to speech into text, it is working fine on iOS
. But in android
it's working fine upto 3 seconds after that recording automaically getting stopped and throws error Error: SpeechRecognitionError msg: error_speech_timeout, permanent: true
And in the manifest
I have included all the necessary permissions
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<queries>
<intent>
<action android:name="android.speech.RecognitionService" />
</intent>
</queries>
home.dart
body: SingleChildScrollView(
reverse: true,
padding: const EdgeInsets.all(30).copyWith(bottom: 150),
child: SubstringHighlight(
text: text,
terms: Command.all,
textStyle: TextStyle(
fontSize: 32.0,
color: Colors.black,
fontWeight: FontWeight.w400,
),
textStyleHighlight: TextStyle(
fontSize: 32.0,
color: Colors.red,
fontWeight: FontWeight.w400,
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: AvatarGlow(
animate: isListening,
endRadius: 75,
glowColor: Theme.of(context).primaryColor,
child: FloatingActionButton(
child: Icon(isListening ? Icons.mic : Icons.mic_none, size: 36),
onPressed: toggleRecording,
),
),
speech_api.dart
import 'package:flutter/cupertino.dart';
import 'package:speech_to_text/speech_to_text.dart';
class SpeechApi {
static final _speech = SpeechToText();
static Future<bool> toggleRecording({
@required Function(String text) onResult,
@required ValueChanged<bool> onListening,
}) async {
if (_speech.isListening) {
_speech.stop();
return true;
}
final isAvailable = await _speech.initialize(
onStatus: (status) => onListening(_speech.isListening),
onError: (e) => print('Error: $e'),
);
if (isAvailable) {
_speech.listen(onResult: (value) => onResult(value.recognizedWords));
}
return isAvailable;
}
}