Flutter Baidu Speech Recognition Plugin

pub

A speech recognition plugin for flutter using BaiduSDK.See the changelog for more information about the function.

Getting Started

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

dependencies:
    baidu_speech_recognition: 0.1.3

Basic Usage

import 'package:baidu_speech_recognition_example/speech_app.dart';

BaiduSpeechRecognition _speechRecognition = BaiduSpeechRecognition();

// initialize 
_speechRecognition.init().then((value) => print(value));
 
// start long speech recognition 
 _speechRecognition.startLongSpeech().then((value) => print(value)); 

 // start speech recognition 60s long
 _speechRecognition.start().then((value) => print(value));  

// cancel recognition 
 _speechRecognition.cancel().then((value) => print(value));
  

The Callback Listener

You can add a listener :

_speechRecognitoin.speechRecognitionEvents
      .listen((String value) {
        // TODO do somethig with the value
      }

The return value is a JSON String :

{
  "type": "The recognition result type",
  "value": "The result"
}

the type have the following value:

typedesc
readyready to speaking...
startdetect start speaking...
stopstop speaking. and return the last result
cancelcancel the last recognition
finishreturn the last recognition
lfinishlong speech return
endend speaking...
meterreturn volume meter level

For iOS developer

Go to 百度ASR download SDK for iOS,then copy BDSClientLib and BDSClientResource to the same directory of you flutter project,the file structure like this:

----------------
  |
  |--Your FLutter Projcet/
  |
  |--BDSClientLib/
  |
  |--BDSCLientResource/

Then open your iOS projcet on Xcode and add the baidu speech SDK library and some resource.

Add BDSClientLib/libBaiduSpeechSDK.a to you project group as "create groups",

Add BDSClientResource/ASR/BDSClientResources to your project group as "create folder references",

Add BDSClientResource/ASR/BDSClientEASRResources to your project group as "create groups".

Add the follow framework to your project:

FrameworkDesc
libc++.tbdFor c/c++ func support
libz.1.2.5.tbdFor gzip support
libsqlite3.0.tbdFor sqlite support
libiconv.2.4.0.tbdSome utility

Finally add Microphone Usage privacy to your info.plist file.

Project Setting

Open you project with xcode and go to Pods, select the baidu_speech_recognition TARGETS, then select the Build Settings Tab, Change Mach-O Type to Static Library.Then go to the Build Phases, make sure all the Headers are Public.

If you have any problem or Error Please make a issue.

For Android developer

First become a baidu Developer

The Follow the guide to add some permission and file you need

Libraries

baidu_speech_recognition

Dart

dart:ui
Built-in types and core primitives for a Flutter application. [...]

Core

dart:async
Support for asynchronous programming, with classes such as Future and Stream. [...]
dart:collection
Classes and utilities that supplement the collection support in dart:core. [...]
dart:convert
Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
dart:core
Built-in types, collections, and other core functionality for every Dart program. [...]
dart:developer
Interact with developer tools such as the debugger and inspector. [...]
dart:math
Mathematical constants and functions, plus a random number generator. [...]
dart:typed_data
Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]

VM

dart:io
File, socket, HTTP, and other I/O support for non-web applications. [...]
dart:isolate
Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]