Package Exports
- react-native-android-voice
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-android-voice) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
react-native-android-voice
react-native-android-voice is a speech-to-text library for React Native for the Android Platform.
##Any Feedback and Ideas are welcome! please use the Issues section above
Documentation
Install
npm install --save react-native-android-voiceUsage
Linking the Library
Add it to your android project
- In
android/settings.gradle
...
include ':VoiceModule', ':app'
project(':VoiceModule').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-voice')- In
android/app/build.gradle
...
dependencies {
...
compile project(':VoiceModule')
}- Register Module (in MainApplication.java)
import com.wmjmc.reactspeech.VoicePackage; // <--- import
public class MainApplication extends Application implements ReactApplication {
...
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VoicePackage()); // <--- added here
}
}Example
import SpeechAndroid from 'react-native-android-voice';
...
async _buttonClick(){
try{
//More Locales will be available upon release.
var spokenText = await SpeechAndroid.startSpeech("Speak yo", SpeechAndroid.GERMAN);
ToastAndroid.show(spokenText , ToastAndroid.LONG);
}catch(error){
switch(error){
case SpeechAndroid.E_VOICE_CANCELLED:
ToastAndroid.show("Voice Recognizer cancelled" , ToastAndroid.LONG);
break;
case SpeechAndroid.E_NO_MATCH:
ToastAndroid.show("No match for what you said" , ToastAndroid.LONG);
break;
case SpeechAndroid.E_SERVER_ERROR:
ToastAndroid.show("Google Server Error" , ToastAndroid.LONG);
break;
/*And more errors that will be documented on Docs upon release*/
}
}
}
...This will automatically start recognizing and adjusting for the German Language. On release I'll update these docs with every single Locale available.
Methods
startSpeech(prompt, locale)
Initializes the voice recognition activity and returns what you spoke in text.
Arguments
- prompt: String for the text to be displayed by the SpeechRecognizer dialog;
- locale: String for the SpeechRecognizer to set itself for the given Locale; (Accessible through constants. see below available locales)
Locales:
DEFAULT
SpeechAndroid.DEFAULTThis will set the SpeechRecognizer to the default locale of your Android smartphone.
Portugal / Portuguese
SpeechAndroid.PT /*or*/ SpeechAndroid.PORTUGUESEBrazil / Portuguese
SpeechAndroid.BR /*or*/ SpeechAndroid.PORTUGUESE_BRAZILBulgarian
SpeechAndroid.BULGARIANCanada / English
SpeechAndroid.CANADACanada / French
SpeechAndroid.CANADA_FRENCHCzech
SpeechAndroid.CZECHCroatian
SpeechAndroid.CROATIANChinese
SpeechAndroid.CHINA /*or*/ SpeechAndroid.CHINESE /*or*/
SpeechAndroid.SIMPLIFIED_CHINESE /*or*/ SpeechAndroid.TRADITIONAL_CHINESENetherlands / Dutch
SpeechAndroid.DUTCHBelgium / Dutch
SpeechAndroid.DUTCH_BELGIUMEnglish
SpeechAndroid.ENGLISHUK / English
SpeechAndroid.UKUS / English
SpeechAndroid.USAustralia / English
SpeechAndroid.AUSTRALIANew Zealand / English
SpeechAndroid.NEW_ZEALANDSingapore / English
SpeechAndroid.SINGAPOREIndia / English
SpeechAndroid.ENGLISH_INDIAIreland / English
SpeechAndroid.ENGLISH_IRELANDZimbabwe / English
SpeechAndroid.ENGLISH_ZIMBABWEEgypt / Arabic
SpeechAndroid.ARABIC_EGYPTIsrael / Arabic
SpeechAndroid.ARABIC_ISRAELFrance / French
SpeechAndroid.FRANCE /*or*/ SpeechAndroid.FRENCHBelgium / French
SpeechAndroid.FRENCH_BELGIUMSwitzerland / French
SpeechAndroid.FRENCH_SWITZERLANDFinnish
SpeechAndroid.FINNISHDanish
SpeechAndroid.DANISHGermany / German
SpeechAndroid.GERMANY /*or*/ SpeechAndroid.GERMANSwitzerland / German
SpeechAndroid.GERMAN_SWITZERLANDGreek
SpeechAndroid.GREEKHebrew
SpeechAndroid.HEBREWHindi
SpeechAndroid.HINDIHungarian
SpeechAndroid.HUNGARIANItaly / Italian
SpeechAndroid.ITALY /*or*/ SpeechAndroid.ITALIANSwitzerland / Italian
SpeechAndroid.ITALIAN_SWITZERLANDIndonesian
SpeechAndroid.INDONESIANLatvian
SpeechAndroid.LATVIANLithuanian
SpeechAndroid.LITHUANIANNorwegian
SpeechAndroid.NORWEGIANJapan
SpeechAndroid.JAPAN /*or*/ SpeechAndroid.JAPANESEPolish
SpeechAndroid.POLISHRussian
SpeechAndroid.RUSSIANRomanian
SpeechAndroid.ROMANIANSpanish
SpeechAndroid.SPANISHCatalan
SpeechAndroid.CATALANUS / Spanish
SpeechAndroid.SPANISH_USSerbian
SpeechAndroid.SERBIANSlovak
SpeechAndroid.SLOVAKSlovenian
SpeechAndroid.SLOVENIANSwedish
SpeechAndroid.SWEDISHKorea
SpeechAndroid.KOREA /*or*/ SpeechAndroid.KOREANTaiwan
SpeechAndroid.TAIWANPhilippines / Tagalog
SpeechAndroid.TAGALOG_PHILIPPINESThai
SpeechAndroid.THAITurkish
SpeechAndroid.TURKISHUkrainian
SpeechAndroid.UKRAINIANVietnamese
SpeechAndroid.VIETNAMESEErrors
E_ACTIVITY_DOES_NOT_EXIST
SpeechAndroid.E_ACTIVITY_DOES_NOT_EXISTGeneric error on current Activity not existing.
E_VOICE_CANCELLED
SpeechAndroid.E_VOICE_CANCELLEDVoice Recognizer was cancelled
E_FAILED_TO_SHOW_VOICE
SpeechAndroid.E_FAILED_TO_SHOW_VOICEVoice Recognizer failed to initialize
E_AUDIO_ERROR
SpeechAndroid.E_AUDIO_ERRORVoice Recognizer encountered some error with the Audio received
E_NETWORK_ERROR
SpeechAndroid.E_NETWORK_ERRORNetwork error while attempting connection with Google's Servers
E_NO_MATCH
SpeechAndroid.E_NO_MATCHVoice Recognizer did not find any match
E_SERVER_ERROR
SpeechAndroid.E_SERVER_ERRORGoogle's Servers encountered an error while processing the request
License
The MIT License (MIT)
Copyright © 2015 João Cunha
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.