npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@red-mobile/cordova-plugin-speech-recognition

v1.3.0

Published

Cordova Plugin for Speech Recognition

Downloads

23

Readme

cordova-plugin-speech-recognition

This is a cordova plugin for Speech Recognition.

Installation

cordova plugin add cordova-plugin-speechrecognition

Supported Platforms

  • Android

Usage

This plugin requires internet connection.

isRecognitionAvailable()

window.plugins.speechRecognition.isRecognitionAvailable(
  Function successCallback, Function errorCallback)

Result of success callback is a Boolean.

startListening()


let options = {
  String language,
  Number matches,
  String prompt,      // Android only
  Boolean showPopup,  // Android only
  Boolean showPartial
}

window.plugins.speechRecognition.startListening(
  Function successCallback, Function errorCallback, Object options)

This method has an options parameter with the following optional values:

  • language {String} used language for recognition (default "en-US")
  • matches {Number} number of return matches (default 5, on iOS: maximum number of matches)
  • prompt {String} displayed prompt of listener popup window (default "", Android only)
  • showPopup {Boolean} display listener popup window with prompt (default true, Android only)
  • showPartial {Boolean} Allow partial results to be returned (default false)

Result of success callback is an Array of recognized terms.

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 stopListening() method.

If you set showPartial to true on iOS the success callback will be called multiple times until stopListening() called.

stopListening()

window.plugins.speechRecognition.stopListening(
  Function successCallback, Function errorCallback)

Stop the recognition process. No return value.

getSupportedLanguages()

window.plugins.speechRecognition.getSupportedLanguages(
  Function successCallback, Function errorCallback)

Result of success callback is an Array of supported languages.

// getSupportedLanguages result on Android:

let supportedLanguagesAndroid = [
  "af-ZA",
  "id-ID",
  "ms-MY",
  "ca-ES",
  "cs-CZ",
  "da-DK",
  "de-DE",
  "en-AU",
  "en-CA",
  "en-001",
  "en-IN",
  "en-IE",
  "en-NZ",
  "en-PH",
  "en-ZA",
  "en-GB",
  "en-US",
  "es-AR",
  "es-BO",
  "es-CL",
  "es-CO",
  "es-CR",
  "es-EC",
  "es-US",
  "es-SV",
  "es-ES",
  "es-GT",
  "es-HN",
  "es-MX",
  "es-NI",
  "es-PA",
  "es-PY",
  "es-PE",
  "es-PR",
  "es-DO",
  "es-UY",
  "es-VE",
  "eu-ES",
  "fil-PH",
  "fr-FR",
  "gl-ES",
  "hr-HR",
  "zu-ZA",
  "is-IS",
  "it-IT",
  "lt-LT",
  "hu-HU",
  "nl-NL",
  "nb-NO",
  "pl-PL",
  "pt-BR",
  "pt-PT",
  "ro-RO",
  "sl-SI",
  "sk-SK",
  "fi-FI",
  "sv-SE",
  "vi-VN",
  "tr-TR",
  "el-GR",
  "bg-BG",
  "ru-RU",
  "sr-RS",
  "uk-UA",
  "he-IL",
  "ar-IL",
  "ar-JO",
  "ar-AE",
  "ar-BH",
  "ar-DZ",
  "ar-SA",
  "ar-KW",
  "ar-MA",
  "ar-TN",
  "ar-OM",
  "ar-PS",
  "ar-QA",
  "ar-LB",
  "ar-EG",
  "fa-IR",
  "hi-IN",
  "th-TH",
  "ko-KR",
  "cmn-Hans-CN",
  "cmn-Hans-HK",
  "cmn-Hant-TW",
  "yue-Hant-HK",
  "ja-JP",
];

// getSupportedLanguages result on iOS:

let supportedLanguagesIOS = [
  "nl-NL",
  "es-MX",
  "zh-TW",
  "fr-FR",
  "it-IT",
  "vi-VN",
  "en-ZA",
  "ca-ES",
  "es-CL",
  "ko-KR",
  "ro-RO",
  "fr-CH",
  "en-PH",
  "en-CA",
  "en-SG",
  "en-IN",
  "en-NZ",
  "it-CH",
  "fr-CA",
  "da-DK",
  "de-AT",
  "pt-BR",
  "yue-CN",
  "zh-CN",
  "sv-SE",
  "es-ES",
  "ar-SA",
  "hu-HU",
  "fr-BE",
  "en-GB",
  "ja-JP",
  "zh-HK",
  "fi-FI",
  "tr-TR",
  "nb-NO",
  "en-ID",
  "en-SA",
  "pl-PL",
  "id-ID",
  "ms-MY",
  "el-GR",
  "cs-CZ",
  "hr-HR",
  "en-AE",
  "he-IL",
  "ru-RU",
  "de-CH",
  "en-AU",
  "de-DE",
  "nl-BE",
  "th-TH",
  "pt-PT",
  "sk-SK",
  "en-US",
  "en-IE",
  "es-CO",
  "uk-UA",
  "es-US",
];

hasPermission()

window.plugins.speechRecognition.hasPermission(
  Function successCallback, Function errorCallback)

Result of success callback is a Boolean.

requestPermission()

window.plugins.speechRecognition.requestPermission(
  Function successCallback, Function errorCallback)

This method requests access permission to system resources if it was not granted before.

Ionic Usage

import { SpeechRecognition } from '@ionic-native/speech-recognition';

constructor(private speechRecognition: SpeechRecognition) { }

...

// Check feature available
SpeechRecognition.isRecognitionAvailable()
  .then((available: boolean) => console.log(available))

// Start the recognition process
SpeechRecognition.startListening(options)
  .subscribe(
    (matches: Array<string>) => console.log(matches),
    (onerror) => console.log('error:', onerror)
  )

// Stop the recognition process (iOS only)
SpeechRecognition.stopListening()

// Get the list of supported languages
SpeechRecognition.getSupportedLanguages()
  .then(
    (languages: Array<string>) => console.log(languages),
    (error) => console.log(error)
  )

// Check permission
SpeechRecognition.hasPermission()
  .then((hasPermission: boolean) => console.log(hasPermission))

// Request permissions
SpeechRecognition.requestPermission()
  .then(
    () => console.log('Granted'),
    () => console.log('Denied')
  )

Required: ionic-native/speech-recognition

See Ionic Native documentation.

Android Quirks

Requirements

  • cordova-android v5.0.0
  • Android API level 14
  • <android:launchMode> must not be singleInstance. It can be singleTask, standard, singleTop.
  • RECORD_AUDIO permission

How it works

It uses Speech API of Google. The Android public API recognizes when the speech is over and automatically begins the parsing process. The delay of result depends on the network quality.

Further readings