0

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;
  }
}
Anand
  • 4,355
  • 2
  • 35
  • 45

1 Answers1

0

Error speech timeout generally means that you haven't spoken anything or the timeout has occurred without any speech. This plugin is generally for doing speech recognition for short interval of time. If there is silence for (let's say 3 seconds) then it automatically exits because there hasn't been any speech spoken. That's what speech timeout means.

From it's docs in troubleshooting section:

Speech recognition stops after a brief pause on Android
 
Android speech recognition has a very short timeout when the
speaker pauses. The duration seems to vary by device and
version of the Android OS. In the devices I've used none have 
had a pause longer than 5 seconds. Unfortunately there 
appears to be no way to change that behaviour.

Also this plugin is for short term recognition not continuous recognition

From it's docs

There have been a number of questions about how to 
achieve continuous speech recognition using this plugin. 
Currently the plugin is designed for short intermittent 
use, like when expecting a response to a question, or 
issuing a single voice command. Issue #63 is the current 
home for that discussion. There is not yet a way to 
achieve this goal using the Android or iOS speech 
recognition capabilities.

For more information see: speech_to_text

Just a Person
  • 1,276
  • 1
  • 5
  • 23