vais_speech 1.0.7

Flutter Android iOS

A new Flutter plugin.

VAIS Speech #

Build Status

For easy integration with VAIS Speech service.

Features #

  • Streaming recognition (up to 1 minutes)
  • Offline record audio and recognition (up to 1 hour)

Installation #

Add this to your package's pubspec.yaml file

  vais_speech: [Current version]

How to use? #

VAIS Speech has 2 parts :

  • Record Audio ( Offline and Streaming Support )
  • Uploaded audio following status
  • Get text by speech

Before started

Android :

Set up permission related to record in AndroidManifest.xml, as below

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

add a service in app

<service android:name="tsyliveaudiorecord.live_audio_record.AudioRecordService"/>
iOS :

The same with iOS in Info.plist

	<string>App need to use music because of retrieving your need uploading file.</string>
Flutter side :

Initialize VAIS instance to use :

final vaisSpeech = VaisSpeech(<YOUR_TOKEN>)

Record Audio:

VAIS Speech have 2 modes to use and you need to decide which mode should be use :

  • Offline mode (default)
  • Streaming mode

  1. Get VAIS Speech Audio and initialize it before recording
final vaisSpeechAudio = vaisSpeech.vaisSpeechAudio; // Get VAIS Speech Audio
await vaisSpeechAudio.init(...) // then initilize it

More about .init() function :

| Function | Properties | | ------ | ------ | | Future init(String path, {AudioFormat audioFormat, int sampleRate = 16000, RecordMode recordMode = RecordMode.Offline}) | path : Your recording path - recordMode : Your recording mode | #

  1. Add Listener to observer your recording. E.g: duration, settings, streaming text (if your are in streaming mode) ...) This method should be call before starting.
addListener(VaisSpeechCallback listener)see more VaisSpeechCallback
VaisSpeechCallbackThis callback includes 3 methods : onGeneratedSpeechText / onDurationChanged / onConnectionChanged
  • onGeneratedSpeechText : Fired when there's some texts are translated (Streaming mode only)
  • onConnectionChanged : Fired when the connection with our services is closed (Streaming mode only)
  • onDurationChanged : duration of your recording (for show duration for e.g).

  1. Start Recording : Simply call .start to start recording
    await vaisSpeechAudio.start();

  1. Pause Recording (Offline mode Only) : You will get an Exception when call it in Streaming Mode
    await vaisSpeechAudio.pause();

  1. Resume Recording (Offline mode Only) : You will get an Exception when call it in Streaming Mode
    await vaisSpeechAudio.resume();

  1. Stop Recording :
    await vaisSpeechAudio.stop();

Upload Recorded Audio:

After recording, call .startAsr() to upload your local Audio. This function will return a AudioId

    await vaisSpeechAudio.startAsr(...);
Futurepath : your located audio file - finalName (optional) your custom audio name

Following status of the Recorded Audio:

    var audioStatus = await vaisSpeechAudio.getProgress(...);
Futureaudio : your audio id after uploading. This will be return a AudioStatus model

Get transcript of the Recorded Audio:

    final transcript = await vaisSpeechAudio.getTranscript();
Futureaudio : your audio id after uploading. This will be return a TranscriptResponse model, you should .data to get a transcript list