Registry / communication / react-native-google-cloud-speech-to-text

react-native-google-cloud-speech-to-text

JSON →
library0.5.4jsnpmunverified

A React Native module for streaming speech recognition using the Google Cloud Speech-to-Text API via gRPC. Version 0.5.4 supports Android only (iOS coming soon) and requires React Native >= 0.60. Configured to read API key from google-services.json by default, but allows runtime override via `setApiKey()`. Differentiator: provides low-level streaming events (voice start, voice end, speech recognized, speech recognizing) for fine-grained control, unlike higher-level wrappers. The library ships TypeScript definitions and exposes event types. Release cadence is irregular; the module is experimental with limited iOS support.

npm install react-native-google-cloud-speech-to-text
INSTALL
IMPORT
SIG · REACT-NATIVE-GOOGL
R
react-native-google-cloud-speech-to-text
communicationjavascriptv0.5.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GoogleCloudSpeechToText
import GoogleCloudSpeechToText from 'react-native-google-cloud-speech-to-text'
import { GoogleCloudSpeechToText } from 'react-native-google-cloud-speech-to-text'
Default export is the main module object. Named import will fail.
SpeechRecognizeEvent
import GoogleCloudSpeechToText, { SpeechRecognizeEvent } from 'react-native-google-cloud-speech-to-text'
const { SpeechRecognizeEvent } = require('react-native-google-cloud-speech-to-text')
TypeScript types are exported as named exports. In CJS, require() may not work for types; use ESM import style.
VoiceStartEvent
import { VoiceStartEvent } from 'react-native-google-cloud-speech-to-text'
import GoogleCloudSpeechToText from 'react-native-google-cloud-speech-to-text'; GoogleCloudSpeechToText.VoiceStartEvent
TypeScript event types are exported separately, not attached to the default export.
require('react-native-google-cloud-speech-to-text')
const GCSpeech = require('react-native-google-cloud-speech-to-text').default;
const GCSpeech = require('react-native-google-cloud-speech-to-text')
With CJS, the default export is under .default. Omitting .default will give an empty object.

Sets up and runs streaming speech recognition with event listeners, API key, and permission handling.

import React, { useEffect } from 'react'; import { View, Button, PermissionsAndroid } from 'react-native'; import GoogleCloudSpeechToText, { SpeechRecognizeEvent, VoiceStartEvent, SpeechErrorEvent, VoiceEvent, SpeechStartEvent, } from 'react-native-google-cloud-speech-to-text'; // Request audio permission (Android) PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.RECORD_AUDIO, { title: 'Microphone Permission', message: 'App needs access to microphone for speech recognition.', buttonPositive: 'Grant', }); // Optionally set API key GoogleCloudSpeechToText.setApiKey(process.env.GOOGLE_API_KEY ?? ''); // Set up event listeners const onSpeechRecognized = (result: SpeechRecognizeEvent) => { console.log('Transcript:', result.transcript); }; GoogleCloudSpeechToText.onSpeechRecognized(onSpeechRecognized); // Start recognition const start = async () => { const result: SpeechStartEvent = await GoogleCloudSpeechToText.start({ speechToFile: false, locale: 'en-US', }); console.log('Started', result); }; // Stop recognition const stop = async () => { await GoogleCloudSpeechToText.stop(); GoogleCloudSpeechToText.removeListeners(); }; export default function App() { return ( <View> <Button title="Start" onPress={start} /> <Button title="Stop" onPress={stop} /> </View> ); }
Debug
Known issues
breakingiOS not yet supported — module currently Android-only.
fix
Use on Android or wait for iOS update. React Native module may crash on iOS.
affects: all
gotchaDefault API key is read from google-services.json (Android). setApiKey() overrides it — must be called before start().
fix
Either configure google-services.json or call GoogleCloudSpeechToText.setApiKey('your-key') early.
affects: all
gotchaEvent listeners (onVoice, onVoiceStart, etc.) do not return cleanup functions; must manually call removeListeners() during unmount.
fix
Call GoogleCloudSpeechToText.removeListeners() in useEffect cleanup or componentWillUnmount.
affects: all
deprecatedThe 'speechToFile' option may be removed or behavior may change; currently marked as 'coming soon'.
fix
Set speechToFile: false for now; monitor updates for file recording feature.
affects: ~0.5.4
gotchaGoogle Cloud speech API requires billing enabled and API key whitelisted for Speech-to-Text.
fix
Follow Google Cloud quickstart to enable the API and create a key with correct restrictions.
affects: all
Errors
Common errors & fixes
GoogleCloudSpeechToText is not a function
Misunderstanding of the default import; trying to call it as a function instead of object method.
fix
Use GoogleCloudSpeechToText.start() not GoogleCloudSpeechToText()
Cannot read property 'start' of undefined
CJS require() did not access .default
fix
const GCSpeech = require('react-native-google-cloud-speech-to-text').default;
Speech error: API key not valid. Please pass a valid API key.
Missing or incorrect API key configuration.
fix
Ensure google-services.json is correctly placed (Android) or call setApiKey() with a valid key before start().
PermissionsAndroid is not defined
Trying to use PermissionsAndroid without importing from 'react-native'.
fix
import { PermissionsAndroid } from 'react-native';
Upgrade
Version history
0.5.4latest on npm
Audit
Dependencies
reactrequiredPeer dependency for React components and hooks.
react-nativerequiredPeer dependency for React Native platform APIs and native module integration.
Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
react-native-google-cloud-speech-to-text — npm install react-native-google-cloud-speech-to-text · libregistry