Giter Site home page Giter Site logo

Comments (5)

mingxun avatar mingxun commented on July 19, 2024 1

I have the same issue when running on simulator. But it works fine on real device. Hope this helps other people who got the same issue.

from speech_recognition.

vinvantest avatar vinvantest commented on July 19, 2024

Looks like after google search I found Error code 2 means Network_error. Still not sure how to fix it in android-emulator x86 in Flutter.

from speech_recognition.

vinvantest avatar vinvantest commented on July 19, 2024

And here is the complete code file Flutter

import 'package:flutter/material.dart';
import 'package:speech_recognition/speech_recognition.dart';
import 'package:tts/tts.dart';

class SpeechBot extends StatefulWidget {
@OverRide
_SpeechBotState createState() => new _SpeechBotState();
}

class _SpeechBotState extends State {
SpeechRecognition _speech;

bool _speechRecognitionAvailable = false;
bool _isListening = false;

String transcription = '';

String _currentLocale = 'en_US';

@OverRide
initState() {
super.initState();
activateSpeechRecognizer();
}

// Platform messages are asynchronous, so we initialize in an async method.
void activateSpeechRecognizer() {
print('_SpeechBotState.activateSpeechRecognizer... ');
_speech = new SpeechRecognition();
_speech.setAvailabilityHandler(onSpeechAvailability);
_speech.setCurrentLocaleHandler(onCurrentLocale);
_speech.setRecognitionStartedHandler(onRecognitionStarted);
_speech.setRecognitionResultHandler(onRecognitionResult);
_speech.setRecognitionCompleteHandler(onRecognitionComplete);
_speech
.activate()
.then((res) => setState(() => _speechRecognitionAvailable = res));
}

@OverRide
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('SpeechRecognition'),
),
body: new Padding(
padding: new EdgeInsets.all(8.0),
child: new Center(
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
new Expanded(
child: new Container(
padding: const EdgeInsets.all(8.0),
color: Colors.grey.shade200,
child: new Text(transcription))),
_buildButton(
onPressed: _speechRecognitionAvailable && !_isListening
? () => start()
: null,
label: _isListening
? 'Listening...'
: 'Listen ($_currentLocale)',
),
_buildButton(
onPressed: _isListening ? () => cancel() : null,
label: 'Cancel',
),
_buildButton(
onPressed: _isListening ? () => stop() : null,
label: 'Stop',
),
],
),
)),
),
);
}

Widget _buildButton({String label, VoidCallback onPressed}) => new Padding(
padding: new EdgeInsets.all(12.0),
child: new RaisedButton(
color: Colors.cyan.shade600,
onPressed: onPressed,
child: new Text(
label,
style: const TextStyle(color: Colors.white),
),
));

void start() => _speech
.listen(locale: _currentLocale)
.then((result) => print('_SpeechBotState.start => result $result'));

void cancel() => _speech.cancel().then((result) => setState(() {
_isListening = result;
print('_speech.cancel result is $result');
}));

void stop() =>
_speech.stop().then((result) => setState(() => _isListening = result));

void onSpeechAvailability(bool result) =>
setState(() => _speechRecognitionAvailable = result);

void onCurrentLocale(String locale) => setState(() {
_currentLocale = locale;
print('Your currentLocale is $_currentLocale');
});

void onRecognitionStarted() => setState(() => _isListening = true);

void onRecognitionResult(String text) => setState(() {
transcription = text;
print('your transcription is $transcription');
});

void onRecognitionComplete() => setState(() {
_isListening = false;
print('onRecongintionComplete the transcript is $transcription');
Tts.speak(transcription);
});
}

from speech_recognition.

mahendraHegde avatar mahendraHegde commented on July 19, 2024

Looks like after google search I found Error code 2 means Network_error. Still not sure how to fix it in android-emulator x86 in Flutter.

Same issue here... Any luck???

from speech_recognition.

toshiossada avatar toshiossada commented on July 19, 2024

Same issue here

from speech_recognition.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.