This is cordova plugin for Speech Recognition and Text to Speech.
cordova plugin add cordova-plugin-speech
- Android
- iOS
This plugin works with internet connection and without internet if language package available on device.
Speech.supportedLanguages
[]String
- Returns list of supported Speech to Text language models.
Speech.getSupportedVoices(Function successCallback, Function errorCallback)
Result of success callback is an Array of supported voices.
Speech.supportedLanguages
String
- Returns systems default Speech to Text language model.
let options = {
Number pitchRate,
Number speechRate,
String language
}
Speech.speakOut(String message, Function successCallback, Function errorCallback, Object options)
message
- {String} message for speaking.
Result of success callback is an String
of TTS states as below:
tts-start
States that TTS started.tts-end
States that TTS ended.
This method has an options parameter with the following optional values:
pitchRate
{Number} used for TTS pitch rate.
iOS
- The default pitch is 1.0. Allowed values are in the range from 0.5 (for lower pitch) to 2.0 (for higher pitch).Android
- The default pitch is 1.0, lower values lower the tone of the synthesized voice, greater values increase it.
speechRate
{Number} used for TTS speech rate.
iOS
- The default speech rate is 0.5. Lower values correspond to slower speech, and vice versa.Android
- The default speech rate is 1.0. Lower values correspond to slower speech, and vice versa.
language
{String} used for TTS speech voice.
iOS
- UseSpeech.getSupportedVoices()
to get voices and useselectedVoice.language
as input.Android
- UseSpeech.getSupportedVoices()
to get voices and useselectedVoice.name
as input.
let options = {
String language
}
Speech.initRecognition(
Function successCallback, Function errorCallback, Object options)
Result of success callback is an Object
of recognition features as below:
offlineRecognitionAvailable
{Boolean} states that offline speech recognition is available or not. For Android it's values is always true.
This method has an options parameter with the following optional values:
language
{String} used language for recognition (default is systems default lanuguage model).
let options = {
Boolean partialResultRequired,
Boolean offlineRecognitionRequired
}
Speech.startRecognition(
Function successCallback, Function errorCallback, Object options)
Result of success callback is an Object
of recognized terms:
isFinal
{Boolean} In case of partial result it isfalse
otherwise it'strue
.text
{String} Recognized text.
This method has an options parameter with the following optional values:
partialResultRequired
{Boolean} Allow partial results to be returned (defaultfalse
)offlineRecognitionRequired
{Boolean} Enables offline speech recognition if language model available (defaultfalse
)
There is a difference between Android and iOS platforms. On Android speech recognition stops when the speaker finishes speaking (at end of sentence). On iOS the user has to stop manually the recognition process by calling stopRecognition() method.
Speech.stopRecognition(
Function successCallback, Function errorCallback)
Stop the recognition process. Returns true
.
- cordova-android v5.0.0
- Android API level 14
- RECORD_AUDIO permission
- https://developer.android.com/reference/android/speech/package-summary.html
- https://developer.android.com/reference/android/speech/SpeechRecognizer.html
- XCode 8.0 (requires 10.12+ macOS Sierra or 10.11.5+ OS X El Capitan)
- iOS 10
- NSMicrophoneUsageDescription permission
- NSSpeechRecognitionUsageDescription permission
- https://developer.apple.com/reference/speech?language=swift
- https://developer.apple.com/reference/speech/sfspeechrecognizer?language=swift
cordova-plugin-speech is licensed under the MIT Open Source license. For more information, see the LICENSE file in this repository.