react-native-android-voice is a speech-to-text library for React Native for the Android Platform with Persian locale support.
##Any Feedback and Ideas are welcome! please use the Issues section above
npm install --save react-native-android-voice-persian
yarn add react-native-android-voice-persian- In
android/settings.gradle
...
include ':VoiceModule', ':app'
project(':VoiceModule').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-voice-persian')- 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
}
}import SpeechAndroid from 'react-native-android-voice-persian';
...
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.
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)
SpeechAndroid.DEFAULTThis will set the SpeechRecognizer to the default locale of your Android smartphone.
SpeechAndroid.PT /*or*/ SpeechAndroid.PORTUGUESESpeechAndroid.BR /*or*/ SpeechAndroid.PORTUGUESE_BRAZILSpeechAndroid.BULGARIANSpeechAndroid.CANADASpeechAndroid.CANADA_FRENCHSpeechAndroid.CZECHSpeechAndroid.CROATIANSpeechAndroid.CHINA /*or*/ SpeechAndroid.CHINESE /*or*/
SpeechAndroid.SIMPLIFIED_CHINESE /*or*/ SpeechAndroid.TRADITIONAL_CHINESESpeechAndroid.DUTCHSpeechAndroid.DUTCH_BELGIUMSpeechAndroid.ENGLISHSpeechAndroid.UKSpeechAndroid.USSpeechAndroid.AUSTRALIASpeechAndroid.NEW_ZEALANDSpeechAndroid.SINGAPORESpeechAndroid.ENGLISH_INDIASpeechAndroid.ENGLISH_IRELANDSpeechAndroid.ENGLISH_ZIMBABWESpeechAndroid.ARABIC_EGYPTSpeechAndroid.ARABIC_ISRAELSpeechAndroid.FRANCE /*or*/ SpeechAndroid.FRENCHSpeechAndroid.FRENCH_BELGIUMSpeechAndroid.FRENCH_SWITZERLANDSpeechAndroid.FINNISHSpeechAndroid.DANISHSpeechAndroid.GERMANY /*or*/ SpeechAndroid.GERMANSpeechAndroid.GERMAN_SWITZERLANDSpeechAndroid.GREEKSpeechAndroid.HEBREWSpeechAndroid.HINDISpeechAndroid.HUNGARIANSpeechAndroid.ITALY /*or*/ SpeechAndroid.ITALIANSpeechAndroid.ITALIAN_SWITZERLANDSpeechAndroid.INDONESIANSpeechAndroid.LATVIANSpeechAndroid.LITHUANIANSpeechAndroid.NORWEGIANSpeechAndroid.JAPAN /*or*/ SpeechAndroid.JAPANESESpeechAndroid.POLISHSpeechAndroid.PERSIANSpeechAndroid.RUSSIANSpeechAndroid.ROMANIANSpeechAndroid.SPANISHSpeechAndroid.CATALANSpeechAndroid.SPANISH_USSpeechAndroid.SERBIANSpeechAndroid.SLOVAKSpeechAndroid.SLOVENIANSpeechAndroid.SWEDISHSpeechAndroid.KOREA /*or*/ SpeechAndroid.KOREANSpeechAndroid.TAIWANSpeechAndroid.TAGALOG_PHILIPPINESSpeechAndroid.THAISpeechAndroid.TURKISHSpeechAndroid.UKRAINIANSpeechAndroid.VIETNAMESESpeechAndroid.E_ACTIVITY_DOES_NOT_EXISTGeneric error on current Activity not existing.
SpeechAndroid.E_VOICE_CANCELLEDVoice Recognizer was cancelled
SpeechAndroid.E_FAILED_TO_SHOW_VOICEVoice Recognizer failed to initialize
SpeechAndroid.E_AUDIO_ERRORVoice Recognizer encountered some error with the Audio received
SpeechAndroid.E_NETWORK_ERRORNetwork error while attempting connection with Google's Servers
SpeechAndroid.E_NO_MATCHVoice Recognizer did not find any match
SpeechAndroid.E_SERVER_ERRORGoogle's Servers encountered an error while processing the request