import {TurboModuleRegistry, type TurboModule} from 'react-native'; import type {EventEmitter} from '../node_modules/react-native/Libraries/Types/CodegenTypesNamespace'; export type VoiceQuality = 'Default' | 'Enhanced'; export interface EventProps { /** * The utterance ID */ id: string; } export interface ProgressEventProps extends EventProps { /** * The text being spoken length */ length: number; /** * The current position in the spoken text */ location: number; } export interface VoiceProps { /** The name of the voice */ name: string; /** The quality level of the voice */ quality: VoiceQuality; /** The language code of the voice (e.g., 'en-US', 'fr-FR') */ language: string; /** The unique identifier for the voice */ identifier: string; } export interface VoiceOptions { /** * If `true`, audio from other apps will be temporarily lowered (ducked) while speech is active. * This is for critical announcements (e.g., navigation) and takes priority over `silentMode` on iOS. * @default false */ ducking?: boolean; /** * Determines how speech audio interacts with the device's silent (ringer) switch. * This option is ignored if `ducking` is `true`. * @platform iOS * * - `obey`: (Default) Does not change the app's audio session. Speech follows the system default. * - `respect`: Speech will be silenced by the ringer switch. Use for non-critical audio. * - `ignore`: Speech will play even if the ringer is off. Use for critical audio when ducking is not desired. */ silentMode?: 'obey' | 'respect' | 'ignore'; /** The language code to use (e.g., 'en', 'fr', 'en-US', 'fr-FR') */ language?: string; /** Volume level from 0.0 to 1.0 */ volume?: number; /** Specific voice identifier to use */ voice?: string; /** * Pitch multiplier from 0.5 to 2.0 * - `Android`: (0.1 - 2.0) * - `iOS`: (0.5 - 2.0) */ pitch?: number; /** * Speech rate * - `Android`: (0.1 - 2.0) * - `iOS`: (`AVSpeechUtteranceMinimumSpeechRate` - `AVSpeechUtteranceMaximumSpeechRate`) */ rate?: number; } export interface EngineProps { /** * The unique system identifier for the engine. * This is typically the package name (e.g., "com.google.android.tts") */ name: string; /** * The human-readable display name for the engine (e.g., "Google Text-to-Speech Engine"). */ label: string; /** * A boolean flag indicating if this is the default engine */ isDefault: boolean; } interface ConstantsProps { /** * The maximum number of characters allowed in a single call to `speak()` or `speakWithOptions()`. * @platform Android */ maxInputLength?: number; } export interface Spec extends TurboModule { getConstants: () => ConstantsProps; //Methods reset: () => void; stop: () => Promise; pause: () => Promise; resume: () => Promise; isSpeaking: () => Promise; speak: (text: string) => Promise; getEngines: () => Promise; configure: (options: VoiceOptions) => void; openVoiceDataInstaller: () => Promise; setEngine: (engineName: string) => Promise; getAvailableVoices: (language?: string) => Promise; speakWithOptions: (text: string, options: VoiceOptions) => Promise; //Listeners readonly onError: EventEmitter; readonly onStart: EventEmitter; readonly onFinish: EventEmitter; readonly onPause: EventEmitter; readonly onResume: EventEmitter; readonly onStopped: EventEmitter; readonly onProgress: EventEmitter; } export default TurboModuleRegistry.getEnforcing('RNSpeech');