googlecloudspeech 0.1.3

  • Readme
  • Changelog
  • Example
  • Installing
  • new57

google_cloud_speech #

Flutter plugin for google speech api

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

0.0.1 #

  • Flutter plugin initialized

0.1.0 #

  • Google speech API - v1 works for speech:recognize and operations:list

0.1.1 #

  • Minor bump, corrected example

0.1.2 #

  • Code prettified

0.1.3 #

  • Convert audio file to base64 string
  • Support other audio file formats
  • Removed (and untrack) system generated files
  • Added LICENSE

example/lib/main.dart

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';

import 'package:googlecloudspeech/googlecloudspeech.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/services.dart';


void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  // ADD API_KEY HERE
  String _apiKey = '';

  String _audioPath;
  String _response;

  @override
  void initState() {
    super.initState();

    _audioPath = '';
    _response  = '';
  }

  Future<void> getListOfOperations() async {

    Map<String, dynamic> responseBody = await GoogleSTTOperations.v1_list({}, _apiKey);

    print("---------- RESPONSE ----------");
    print(responseBody);
    print("------------------------------");
  }

  Future<void> speechToText() async {

    try {
//      // This is an example asset file. Replace this with a file on the device
//      var bytes            = await rootBundle.load('assets/example_file.flac');
//      String base64audio   = base64.encode(Uint8List.view(bytes.buffer));

      // NOTE: Currently config dictionary supports only file types 'flac' or 'wav'
      Map<String, dynamic> response = await GoogleSTTSpeech.v1_recognize({}, _apiKey, 'file_path', _audioPath);

      print("------ RESPONSE ------");
      print(response);
      print("----------------------");

      setState(() {
        _response = response.toString();
      });
    } catch (e) {
      print(e.toString());
    }
  }

  void _openFileExplorer() async {

    try {
      String path = await FilePicker.getFilePath(type: FileType.audio,);

      setState(() {
        _audioPath = path;
      });

    } on PlatformException catch (e) {
      print("Unsupported operation" + e.toString());
    }
    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner : false,
      home                       : Scaffold(
        appBar : AppBar(title: const Text('google_cloud_speech example'),),
        body   : Center(

            child : Column(
              mainAxisAlignment : MainAxisAlignment.center,

              children : <Widget>[
                Container(
                  height : 60,
                  width  : 270,
                  decoration : BoxDecoration(
                    borderRadius : BorderRadius.circular(10.0),
                    color        : Colors.white,
                  ),

                  child : MaterialButton(
                    highlightColor : Colors.grey[600],
                    shape          : RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),

                    child : Text('Select File', style : TextStyle(fontSize : 25, fontWeight : FontWeight.bold, color : Colors.grey[500])),
                    onPressed: _openFileExplorer,
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(10, 10, 10, 10),

                  child: Text(_audioPath, style: TextStyle(fontSize: 12))
                ),
                Container(
                  height : 60,
                  width  : 270,
                  decoration : BoxDecoration(
                    borderRadius : BorderRadius.circular(10.0),
                    color        : Colors.white,
                  ),

                  child : MaterialButton(
                    highlightColor : Colors.grey[600],
                    shape          : RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),

                    child : Text('Speech 2 Text', style : TextStyle(fontSize : 25, fontWeight : FontWeight.bold, color : Colors.grey[500])),
                    onPressed: () { speechToText(); },
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(10, 10, 10, 10),

                  child: Text(_response, style : TextStyle(fontSize: 12))
                )
              ],
            )
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  googlecloudspeech: ^0.1.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:googlecloudspeech/googlecloudspeech.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
26
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform ios

Because:

  • package:googlecloudspeech/googlecloudspeech.dart that declares support for platforms: android

Package does not support Flutter platform linux

Because:

  • package:googlecloudspeech/googlecloudspeech.dart that declares support for platforms: android

Package does not support Flutter platform macos

Because:

  • package:googlecloudspeech/googlecloudspeech.dart that declares support for platforms: android

Package does not support Flutter platform web

Because:

  • package:googlecloudspeech/googlecloudspeech.dart that declares support for platforms: android

Package does not support Flutter platform windows

Because:

  • package:googlecloudspeech/googlecloudspeech.dart that declares support for platforms: android

Package not compatible with SDK dart

Because:

  • googlecloudspeech that is a package requiring null.

Health suggestions

Fix lib/googlecloudspeech.dart. (-4.89 points)

Analysis of lib/googlecloudspeech.dart reported 10 hints, including:

line 11 col 39: Name non-constant identifiers using lowerCamelCase.

line 11 col 82: Name non-constant identifiers using lowerCamelCase.

line 17 col 25: The value of the local variable 'headers' isn't used.

line 24 col 23: Name non-constant identifiers using lowerCamelCase.

line 36 col 23: Name non-constant identifiers using lowerCamelCase.

Format lib/utils.dart.

Run flutter format to format lib/utils.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
http ^0.12.1 0.12.1
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
http_parser 3.1.4
meta 1.1.8 1.2.2
path 1.7.0
pedantic 1.9.0 1.9.2
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test