android_tts 0.0.2
android_tts: ^0.0.2 copied to clipboard
A TTS plug-in that supports switching engines
example/lib/main.dart
import 'package:android_tts/android_tts.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _androidTtsPlugin = AndroidTts();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
_androidTtsPlugin.openTTSSetting();
},
child: const Text("switch system engine")),
ElevatedButton(
onPressed: () {
_androidTtsPlugin.init();
},
child: const Text("init")),
ElevatedButton(
onPressed: () async {
print(await _androidTtsPlugin.getConfig());
},
child: const Text("print config")),
ElevatedButton(
onPressed: () async {
print(await _androidTtsPlugin.setPitch(pitch: 0.5));
},
child: const Text("setPitch")),
ElevatedButton(
onPressed: () async {
print(await _androidTtsPlugin.setLanguage(
language: 'yue__#Hant'));
},
child: const Text("setLanguage")),
ElevatedButton(
onPressed: () {
_androidTtsPlugin.speak(text: "你好啊中国");
},
child: const Text("speak")),
],
),
),
),
);
}
}