Static

Since

1.1.13

SpeechRecognizer class provides access to the speech recognition service.

Example

import TextArea from '@smartface/native/ui/textarea';
import SpeechRecognizer from '@smartface/native/speechrecognizer';
import Application from '@smartface/native/application';
import Button from '@smartface/native/ui/button';
import System from '@smartface/native/device/system';
var myButton = new Button({
height: 100,
text: "Start Recording"
})
var myTextArea = new TextArea({
height: 100
})
myButton.onPress = function() {
if (!SpeechRecognizer.isRunning()) {
myButton.text = "Stop Recording";
if (System.OS === "iOS") {
startSpeechRecognizer();
}
else if (System.OS === "Android") {
const RECORD_AUDIO_CODE = 1002;
Application.android.requestPermissions(RECORD_AUDIO_CODE, Application.Android.Permissions.RECORD_AUDIO);
Application.android.onRequestPermissionsResult = function(e) {
if (e.requestCode === RECORD_AUDIO_CODE && e.result) {
startSpeechRecognizer();
}
}
}
}
else {
myButton.text = "Start Recording";
SpeechRecognizer.stop();
}

this.layout.addChild(myTextArea);
this.layout.addChild(myButton)
function startSpeechRecognizer() {
SpeechRecognizer.start({
locale : "en_US",
onResult: function(result) {
myTextArea.text = result;
},
onFinish: function(result) {
myButton.text = "Start Recording";
alert("Finish : " + result);
},
onError: function(error) {
myButton.text = "Start Recording";
alert("Error : " + error);
}
});
}

Hierarchy

  • ISpeechRecognizer

Methods

Properties

Methods

  • Starts speech recognition service. Permissions.android#microphone is required for Android platform.

    Method

    start

    Android

    Ios

    Since

    1.1.13

    Parameters

    • params: { locale: string; onResult: ((result: any) => void); onFinish: ((result: any) => void); onError: ((error: { INSUFFICIENT_PERMISSIONS: "INSUFFICIENT_PERMISSIONS"; NETWORK: "NETWORK"; NETWORK_TIMEOUT: "NETWORK_TIMEOUT"; SPEECH_TIMEOUT: "SPEECH_TIMEOUT"; CLIENT: "CLIENT"; SERVER: "SERVER"; android: { AUDIO: "AUDIO"; NO_MATCH: "NO_MATCH"; RECOGNIZER_BUSY: "RECOGNIZER_BUSY" } }) => void) }

      Object describing callbacks

      • locale: string

        IETF language tag for example "en_US"

      • onResult: ((result: any) => void)
          • (result: any): void
          • Triggers when partial recognition results are available.

            Parameters

            • result: any

            Returns void

      • onFinish: ((result: any) => void)
          • (result: any): void
          • Triggers when recognition result is ready.

            Parameters

            • result: any

            Returns void

      • onError: ((error: { INSUFFICIENT_PERMISSIONS: "INSUFFICIENT_PERMISSIONS"; NETWORK: "NETWORK"; NETWORK_TIMEOUT: "NETWORK_TIMEOUT"; SPEECH_TIMEOUT: "SPEECH_TIMEOUT"; CLIENT: "CLIENT"; SERVER: "SERVER"; android: { AUDIO: "AUDIO"; NO_MATCH: "NO_MATCH"; RECOGNIZER_BUSY: "RECOGNIZER_BUSY" } }) => void)
          • (error: { INSUFFICIENT_PERMISSIONS: "INSUFFICIENT_PERMISSIONS"; NETWORK: "NETWORK"; NETWORK_TIMEOUT: "NETWORK_TIMEOUT"; SPEECH_TIMEOUT: "SPEECH_TIMEOUT"; CLIENT: "CLIENT"; SERVER: "SERVER"; android: { AUDIO: "AUDIO"; NO_MATCH: "NO_MATCH"; RECOGNIZER_BUSY: "RECOGNIZER_BUSY" } }): void
          • This event is called after getting errors.

            Parameters

            • error: { INSUFFICIENT_PERMISSIONS: "INSUFFICIENT_PERMISSIONS"; NETWORK: "NETWORK"; NETWORK_TIMEOUT: "NETWORK_TIMEOUT"; SPEECH_TIMEOUT: "SPEECH_TIMEOUT"; CLIENT: "CLIENT"; SERVER: "SERVER"; android: { AUDIO: "AUDIO"; NO_MATCH: "NO_MATCH"; RECOGNIZER_BUSY: "RECOGNIZER_BUSY" } }
              • INSUFFICIENT_PERMISSIONS: "INSUFFICIENT_PERMISSIONS"
              • NETWORK: "NETWORK"
              • NETWORK_TIMEOUT: "NETWORK_TIMEOUT"
              • SPEECH_TIMEOUT: "SPEECH_TIMEOUT"
              • CLIENT: "CLIENT"
              • SERVER: "SERVER"
              • android: { AUDIO: "AUDIO"; NO_MATCH: "NO_MATCH"; RECOGNIZER_BUSY: "RECOGNIZER_BUSY" }
                • AUDIO: "AUDIO"
                • NO_MATCH: "NO_MATCH"
                • RECOGNIZER_BUSY: "RECOGNIZER_BUSY"

            Returns void

    Returns void

  • Stop speech recognition service.

    Method

    stop

    Android

    Ios

    Since

    1.1.13

    Returns void

  • Returns whether speech recognition service runs or not.

    Method

    isRunning

    Returns

    Android

    Ios

    Since

    1.1.13

    Returns boolean

Properties

ios: { isLocaleSupported: any }

Type declaration

  • isLocaleSupported:function
    • Returns speech recognition supported locale or not supported. Locale parameter must be empty to check current locale.

      Method

      isLocaleSupported

      Returns

      Ios

      Since

      1.1.16

      Parameters

      • locale: string

      Returns boolean

Error: { INSUFFICIENT_PERMISSIONS: "INSUFFICIENT_PERMISSIONS"; NETWORK: "NETWORK"; NETWORK_TIMEOUT: "NETWORK_TIMEOUT"; SPEECH_TIMEOUT: "SPEECH_TIMEOUT"; CLIENT: "CLIENT"; SERVER: "SERVER"; android: { AUDIO: "AUDIO"; NO_MATCH: "NO_MATCH"; RECOGNIZER_BUSY: "RECOGNIZER_BUSY" } } & { android: { AUDIO: "AUDIO"; NO_MATCH: "NO_MATCH"; RECOGNIZER_BUSY: "RECOGNIZER_BUSY" } }

Generated using TypeDoc