diff --git a/README.md b/README.md index 7047212..6f9b89a 100644 --- a/README.md +++ b/README.md @@ -3,59 +3,61 @@ [![npm version](https://badge.fury.io/js/react-native-deepgram.svg)](https://badge.fury.io/js/react-native-deepgram) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -**react-native-deepgram** brings Deepgram's AI platform to React Native & Expo. +The complete client for Deepgram's voice AI platform on **React Native** and **Expo** β€” real-time transcription, conversational voice agents, text-to-speech, and text intelligence in a single dependency, with hardware echo cancellation and background-audio support wired up for you. -> βœ… Supports **Speech-to-Text v1** and the new **Speech-to-Text v2 (Flux)** streaming API alongside Text-to-Speech, Text Intelligence, and the Management API. +```bash +yarn add react-native-deepgram +``` + +## At a glance + +| | | +| --- | --- | +| πŸ—£οΈ **Voice Agent** | Full-duplex agents over Deepgram's WebSocket. Hardware AEC on iOS (VPIO) and Android (`VOICE_COMMUNICATION` + `MODE_IN_COMMUNICATION`). Function calling, prompt updates, latency telemetry. | +| πŸŽ™οΈ **Speech-to-Text** | Live PCM streaming over WebSocket on STT v1 *or* Flux v2 (`flux-general-en`). File transcription with summarisation, topics, intents, entities. | +| πŸ”Š **Text-to-Speech** | One-shot HTTP synthesis or low-latency WebSocket streaming with `Speak` / `Flush` / `Clear` / `Close` controls. | +| 🧠 **Text Intelligence** | Summaries, topics, intents, sentiment over text or URLs. | +| πŸ› οΈ **Management API** | Typed wrapper for projects, models, keys, usage, balances, members, invitations, scopes, purchases, and temporary tokens. | +| βš™οΈ **Expo plugin** | One-line install β€” handles permissions, background-audio modes, and Android foreground service automatically. | +| 🧰 **Resilient by default** | Audio interruptions, route changes, headphone unplugging, mediaserverd resets, audio-focus loss, and queue overflow are all handled. | +| πŸ†• **Modern iOS APIs** | `AVAudioApplication.requestRecordPermission` and `AllowBluetoothHFP` on iOS 17+, with safe fallbacks. | + +--- ## Table of contents -1. [Features](#features) -2. [Installation](#installation) -3. [Expo config plugin](#expo-config-plugin) -4. [Configuration](#configuration) -5. [Usage overview](#usage-overview) +1. [Quick start (5 minutes)](#quick-start-5-minutes) +2. [Requirements](#requirements) +3. [Installation](#installation) +4. [Core concepts](#core-concepts) +5. [Audio session, AEC & background](#audio-session-aec--background) 6. [Voice Agent](#voice-agent-usedeepgramvoiceagent) 7. [Speech-to-Text](#speech-to-text-usedeepgramspeechtotext) 8. [Text-to-Speech](#text-to-speech-usedeepgramtexttospeech) 9. [Text Intelligence](#text-intelligence-usedeepgramtextintelligence) 10. [Management API](#management-api-usedeepgrammanagement) -11. [Example app](#example-app) -12. [Roadmap](#roadmap) -13. [Contributing](#contributing) -14. [License](#license) +11. [Expo config plugin reference](#expo-config-plugin-reference) +12. [Common recipes](#common-recipes) +13. [Troubleshooting](#troubleshooting) +14. [Example app](#example-app) +15. [Roadmap](#roadmap) +16. [Contributing](#contributing) +17. [License](#license) --- -## Features +## Quick start (5 minutes) -- πŸ”Š **Live Speech-to-Text** – capture PCM audio and stream it over WebSocket (STT v1 or v2/Flux). -- πŸ“„ **File Transcription** – send audio files/URIs to Deepgram and receive transcripts. -- 🎀 **Text-to-Speech** – synthesize speech with HTTP requests or WebSocket streaming controls. -- πŸ—£οΈ **Voice Agent** – orchestrate realtime conversational agents with microphone capture + audio playback. -- 🧠 **Text Intelligence** – summarisation, topic detection, intents, sentiment and more. -- πŸ› οΈ **Management API** – list models, keys, usage, projects, balances, etc. -- βš™οΈ **Expo config plugin** – automatic native configuration for managed and bare workflows. - ---- - -## Installation +### 1. Install ```bash yarn add react-native-deepgram -# or -npm install react-native-deepgram ``` -### iOS (CocoaPods) - -```bash -cd ios && pod install -``` - -### Expo +### 2. Configure the Expo plugin ```js -// app.config.js +// app.config.js (or app.json under "plugins") module.exports = { expo: { plugins: [ @@ -76,19 +78,115 @@ npx expo prebuild npx expo run:ios # or expo run:android ``` +> Bare React Native? Skip the plugin, run `cd ios && pod install`. The package autolinks via `react-native.config.js`. + +### 3. Configure the SDK once at startup + +```ts +// App.tsx +import { configure } from 'react-native-deepgram'; + +configure({ apiKey: process.env.EXPO_PUBLIC_DEEPGRAM_API_KEY! }); +``` + +> **Never ship raw API keys.** Use `EXPO_PUBLIC_*` env vars, secrets storage, or a backend proxy that mints scoped keys. + +### 4. Stream microphone audio to Deepgram (live STT) + +```tsx +import { useDeepgramSpeechToText } from 'react-native-deepgram'; +import { Button, Text, View } from 'react-native'; + +export function LiveCaption() { + const { + startListening, + stopListening, + state, // { status: 'idle' | 'listening' | 'error' | ... } + transcript, // accumulated final transcript + interimTranscript, // current partial + } = useDeepgramSpeechToText({ + trackState: true, + trackTranscript: true, + live: { punctuate: true, interimResults: true }, + }); + + return ( + + {transcript} {interimTranscript} +