1

Has anyone implemented Speech to text inside a textfield in flutter? I found this plugin but I cant get the example to run. I am using VSCode on windows for this build.

I tried this plugin - speech_recognition 0.3.0+1

1 Answer 1

3

A few small quirks with that plugin/sample:

  • I had to comment out _speech.setErrorHandler(errorHandler);
  • It didn’t implement permission requests, so for Android, I had to first manually enable it from the sample app’s settings. (or you can quickly implement permission_handler)

Otherwise, it is working. So for some simple testing, all you have to do is convert the Text that it uses to display the speech-to-text results to a TextField. This means changing these two lines and initState():

child: new Text(transcription))),

void onRecognitionResult(String text) => setState(() => transcription = text);

To accomodate a TextField with a controller:

TextEditingController _textEditingController;

@override
initState() {
  super.initState();
  activateSpeechRecognizer();
  _textEditingController = new TextEditingController();
}

child: new TextField(controller: _textEditingController))),

void onRecognitionResult(String text) => setState(() => _textEditingController.text = text);

That’s it. Modify as needed.

Sign up to request clarification or add additional context in comments.

1 Comment

how to append the speech output to existing text in text field because onRecognitionResult gets called multiple times?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.