react-native-deepgram
Version:
React Native SDK for Deepgram's AI-powered speech-to-text, real-time transcription, and text intelligence APIs. Supports live audio streaming, file transcription, sentiment analysis, and topic detection for iOS and Android.
35 lines (34 loc) • 949 B
JavaScript
;
import { Buffer } from 'buffer';
export function arrayBufferToBase64(buffer) {
const bytes = new Uint8Array(buffer);
return Buffer.from(bytes).toString('base64');
}
export function createAudioPlayerController() {
let isActive = false;
return {
start: async (sampleRate = 16000, channels = 1) => {
const {
Deepgram
} = await import('../NativeDeepgram');
Deepgram.startPlayer?.(sampleRate, channels);
isActive = true;
},
feed: async audio => {
const {
Deepgram
} = await import('../NativeDeepgram');
const b64 = typeof audio === 'string' ? audio : arrayBufferToBase64(audio);
await Deepgram.feedAudio?.(b64);
},
stop: async () => {
const {
Deepgram
} = await import('../NativeDeepgram');
Deepgram.stopPlayer?.();
isActive = false;
},
isActive: () => isActive
};
}
//# sourceMappingURL=audioUtils.js.map