Flutter: Text to Voice Array
I have an Android App that converts text to voice.
each word/string on the array is a button that when selected it converts to voice.
I am looking to implement this in Flutter.
private TextToSpeech tts;
GridView grid;
String[] words = {
"Flutter",
"Dart",
"React,
"Java"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tts =new TextToSpeech(this, this);
setContentView(R.layout.activity_main);
grid = (GridView) findViewById(R.id.grid);
Can anyone provide a solution in Dart/Flutter?
Thank you.
You may find the tts package for Flutter useful:
https://pub.dartlang.org/packages/tts
Here is the simple example
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(new Scaffold(
body: new Center(
child: new RaisedButton(
onPressed: speak,
child: new Text('Say Hello'),
),
),
));
}
speak() async {
Tts.speak('Hello World');
}
While you may find a more in-depth example here:
https://pub.dartlang.org/packages/tts#-example-tab-
As for wiring this all together:
Can anyone provide a solution in Dart/Flutter?
Here is a simple example using a list to render buttons for each String in the list along with the onPressed actions to speak the words:
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("The App"),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: _buildWords(),
),
),
);
}
List<String> words = ['hello', 'world', 'flutter', 'is', 'awesome'];
List<Widget> _buildWords() {
return words.map((String word) {
return new RaisedButton(
child: new Text(word),
onPressed: () => Tts.speak(word),
);
}).toList();
}
each word/string on the array is a button that when selected it converts to voice.
I am looking to implement this in Flutter.
private TextToSpeech tts;
GridView grid;
String[] words = {
"Flutter",
"Dart",
"React,
"Java"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tts =new TextToSpeech(this, this);
setContentView(R.layout.activity_main);
grid = (GridView) findViewById(R.id.grid);
Can anyone provide a solution in Dart/Flutter?
Thank you.
You may find the tts package for Flutter useful:
https://pub.dartlang.org/packages/tts
Here is the simple example
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(new Scaffold(
body: new Center(
child: new RaisedButton(
onPressed: speak,
child: new Text('Say Hello'),
),
),
));
}
speak() async {
Tts.speak('Hello World');
}
While you may find a more in-depth example here:
https://pub.dartlang.org/packages/tts#-example-tab-
As for wiring this all together:
Can anyone provide a solution in Dart/Flutter?
Here is a simple example using a list to render buttons for each String in the list along with the onPressed actions to speak the words:
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("The App"),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: _buildWords(),
),
),
);
}
List<String> words = ['hello', 'world', 'flutter', 'is', 'awesome'];
List<Widget> _buildWords() {
return words.map((String word) {
return new RaisedButton(
child: new Text(word),
onPressed: () => Tts.speak(word),
);
}).toList();
}
Comments
Post a Comment