speech 0.0.3+1 speech: ^0.0.3+1 copied to clipboard
This plugin provides one method which takes the filename of a (valid) json file containing gcloud speech credentials, uses this to connect to google's speech api and sends a real-time transcript back
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:speech/speech.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _text = "";
int _index = 0;
StreamSubscription<dynamic> listener;
var _icon = [
new Icon(Icons.keyboard_voice),
new Icon(Icons.stop),
];
var _color = [
Colors.cyan,
Colors.red
];
void _buttonPressed() async {
if (_index == 0) listener = transcript("/storage/emulated/0/Download/hypnote.json").listen((data) => _append(data), onError: (error) => print(error));
else listener.cancel();
_switchButton();
}
void _switchButton() => setState(() => _index = (_index + 1) % 2);
void _append(String text) => setState(() => _text += text);
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Life Transcript'),
backgroundColor: Colors.cyan,
),
body: Center(
child: new Text(_text),
),
floatingActionButton: FloatingActionButton(
child: _icon[_index],
backgroundColor: _color[_index],
onPressed: _buttonPressed,
),
),
);
}
}