Comments (5)
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.
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.
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.
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.
Same issue here
from speech_recognition.
Related Issues (20)
- Flutter web? HOT 3
- I/flutter (11568): Unknowm method speech.onError on unclear voice
- Auto detect language HOT 1
- How to implement this plugin with a text field and enable user to modify the text?
- Stop when voice end
- Unknowm method speech.onError HOT 1
- new problem on flutter > iOS build (from android studio) HOT 1
- does not work for Android while is working with iOS
- Is it possible to get the .mp3 file?
- Listen unless user finishes
- Can this be used offline?
- speech_recognition ios build target change HOT 2
- use 2 different SpeechRecognition in one class is not working !! HOT 1
- The stop button does not work
- 2 Bips
- onErrorHandler
- Availability for Mandarin Chinese
- Android local language speech detect and text in local language HOT 1
- Problem after adding AndroidX Compatability HOT 1
- Old SDK required? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from speech_recognition.