Registry /
communication / react-native-google-cloud-speech-to-text
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>
);
}
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.
fixUse GoogleCloudSpeechToText.start() not GoogleCloudSpeechToText()
Cannot read property 'start' of undefined
CJS require() did not access .default
fixconst 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.
fixEnsure 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'.
fiximport { PermissionsAndroid } from 'react-native'; Audit
Dependencies
reactrequiredPeer dependency for React components and hooks.
react-nativerequiredPeer dependency for React Native platform APIs and native module integration.