react-native-google-speech
v3.0.10
Published
React Native extension for audio translation
Downloads
51
Maintainers
Readme
React Native Google Speech
Work in Progress
Module that captures voice from the microphone and translates it to text. Be sure to give permissions of microphone and storage while using it .
It is still being implemented in Ios. Works ONLY in Android.
Installation
npm install react-native-google-speech --save
react-native link
Sample Code
import SpeechTranslatorModule from 'react-native-google-speech';
SpeechTranslatorModule
.startVoiceCapture()
.then(savedFilePath) {
console.log('Recording started');
console.log("Speech Recording Started. The voice is saved at " + savedFilePath);
}
.catch((error) => {
console.log(`Error in startListening${JSON.stringify(error)}`);
});
SpeechTranslatorModule
.stopVoiceCapture()
.then(() => {
console.log('Recording stopped');
})
.catch((error) => {
console.log(`Error stopping Recording${JSON.stringify(error)}`);
});
To initialize and add Listeners
// Put the google auth file in android's assets directory.
// second argument is to state whether the captured voice's audio file should be saved or not.
SpeechTranslatorModule.initSpeechProcessor('authFile.json', true);
//Add calllback listener. Only one listener can be added as of now.
SpeechTranslatorModule.addNewTextListener((response) => {
console.log(response.result);
});
// Adding Error Callback Listener.
SpeechTranslatorModule.addErrorTextListener((error) => {
console.log(`Recieved Error while Translating Text${error}`);
});