我有一个Android应用程序,可将文本转换为语音。阵列上的每个单词/串是一个按钮在被选择时将其转换为声音。我希望在Flutter中实现这一点。
private TextToSpeech tts;
GridView网格;
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);
谁能在Dart / Flutter中提供解决方案?
谢谢。
您可能会发现tts
Flutter的软件包很有用:
https://pub.dartlang.org/packages/tts
这是简单的例子
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');
}
虽然您可以在此处找到更深入的示例:
https://pub.dartlang.org/packages/tts#-example-tab-
至于将所有这些连接在一起:
谁能在Dart / Flutter中提供解决方案?
这是一个简单的示例,使用列表为列表中的每个String以及对单词的onPressed
操作呈现按钮speak
:
@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();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句