Soniox
SDKs

React Native SDK

Build speech-to-text workflows in React Native with real-time API.

Soniox React SDK works with React Native and Expo out of the box, providing the same hooks for real-time speech-to-text. It lets you:

  • Capture audio from the device microphone with a single hook
  • Stream audio to Soniox in real time
  • Receive transcription and translation results as reactive state

Quickstart

Install

Install via your preferred package manager:

npm install @soniox/react @soniox/client
yarn add @soniox/react @soniox/client
pnpm add @soniox/react @soniox/client
bun add @soniox/react @soniox/client

Setup you temporary API key endpoint

In client enviroment (browser, mobile app, React Native, etc.), you don't want to expose your API key to the client. For this reason, you can create a temporary API key endpoint on your server and use it to issue temporary API keys for the client.

Read more about using Temporary API keys with React SDK

Create a custom audio source

Wrap any RN audio streaming library (e.g. @siteed/expo-audio-studio) with the AudioSource interface to stream PCM audio chunks to Soniox

import type { AudioSource, AudioSourceHandlers } from "@soniox/client";

class MyAudioSource implements AudioSource {
  private handlers: AudioSourceHandlers | null = null;

  async start(handlers: AudioSourceHandlers): Promise<void> {
    this.handlers = handlers;

    // Start your audio capture here.
    // Call handlers.onData(chunk) with each audio chunk as an ArrayBuffer.
    // Call handlers.onError(error) if something goes wrong.
    // Call handlers.onMuted?.() / handlers.onUnmuted?.() when the mic is
    // muted or unmuted externally (e.g. OS-level, hardware switch).
  }

  stop(): void {
    // Stop audio capture and release resources.
    this.handlers = null;
  }
}

Create your first real-time session

The core hooks (e.g. useRecording) are platform-agnostic. To use them in React Native, provide a custom AudioSource that streams PCM audio chunks

import { SonioxProvider, useRecording } from "@soniox/react";
import { MyAudioSource } from "./MyAudioSource";

// Create a temporary API key endpoint on your server and use it to issue temporary API keys for the client.
async function fetchApiKey() {
  const res = await fetch("/api/soniox-temporary-key", { method: "POST" });
  const { api_key } = await res.json();
  return api_key;
}

function App() {
  return (
    // Wrap your app with a SonioxProvider and pass the temporary API key getter function
    <SonioxProvider apiKey={fetchApiKey} permissions={null}>
      <Transcription />
    </SonioxProvider>
  );
}

function Transcription() {
  // Create a custom audio source
  const source = useRef(new MyAudioSource()).current;

  // Create a recording session
  const { state, isActive, finalText, partialText, start, stop } = useRecording({
    model: "stt-rt-v4",
    audio_format: "pcm_s16le",
    sample_rate: 16000,
    num_channels: 1,
    source,
  });

  return (
    <View>
      <Text>
        <Text>{finalText}</Text>
        <Text style={{ color: "gray" }}>{partialText}</Text>
      </Text>
      {isActive ? (
        <Button title="Stop" onPress={() => void stop()} />
      ) : (
        <Button title="Start" onPress={start} />
      )}
    </View>
  );
}

Next steps