Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

soniox.md

266 lines8.3 KB

1---
2title: Soniox
3id: soniox-adapter
4order: 3
5description: "Transcribe audio with Soniox speech-to-text models in TanStack AI via the Soniox community adapter."
6keywords:
7 - tanstack ai
8 - soniox
9 - transcription
10 - speech-to-text
11 - asr
12 - community adapter
13---
14​
15The Soniox adapter provides access to Soniox transcription models.
16​
17## Installation
18​
19<!-- ::start:tabs variant="package-manager" mode="install" -->
20​
21react: @soniox/tanstack-ai-adapter
22vue: @soniox/tanstack-ai-adapter
23solid: @soniox/tanstack-ai-adapter
24svelte: @soniox/tanstack-ai-adapter
25preact: @soniox/tanstack-ai-adapter
26angular: @soniox/tanstack-ai-adapter
27vanilla: @soniox/tanstack-ai-adapter
28octane: @soniox/tanstack-ai-adapter
29​
30<!-- ::end:tabs -->
31​
32## Authentication
33​
34Set `SONIOX_API_KEY` in your environment or pass `apiKey` when creating the adapter. Get your API key from the [Soniox Console](https://console.soniox.com).
35​
36## Basic Usage
37​
38```typescript
39import { generateTranscription } from "@tanstack/ai";
40import { sonioxTranscription } from "@soniox/tanstack-ai-adapter";
41import { audioFile } from "./audio";
42​
43const result = await generateTranscription({
44 adapter: sonioxTranscription("stt-async-v3"),
45 audio: audioFile,
46 modelOptions: {
47 enableLanguageIdentification: true,
48 enableSpeakerDiarization: true,
49 },
50});
51​
52console.log(result.text);
53console.log(result.segments);
54```
55​
56## Basic Usage - Custom API Key
57​
58```typescript
59import { generateTranscription } from "@tanstack/ai";
60import { createSonioxTranscription } from "@soniox/tanstack-ai-adapter";
61import { audioFile } from "./audio";
62​
63const adapter = createSonioxTranscription("stt-async-v3", process.env.SONIOX_API_KEY!);
64​
65const result = await generateTranscription({
66 adapter,
67 audio: audioFile,
68});
69```
70​
71## Adapter Configuration
72​
73Use `createSonioxTranscription` to customize the adapter instance:
74​
75```typescript
76import { createSonioxTranscription } from "@soniox/tanstack-ai-adapter";
77​
78const adapter = createSonioxTranscription("stt-async-v3", process.env.SONIOX_API_KEY!, {
79 baseUrl: "https://api.soniox.com",
80 pollingIntervalMs: 1000,
81 timeout: 180000,
82});
83```
84​
85Options:
86​
87- `apiKey` - Override `SONIOX_API_KEY` (required when using `createSonioxTranscription`)
88- `baseUrl` - Custom API base URL. Default is `https://api.soniox.com`
89- `headers` - Additional request headers
90- `timeout` - Transcription timeout in milliseconds (default: 180000)
91- `pollingIntervalMs` - Transcription polling interval in milliseconds (default: 1000)
92​
93See the [Soniox regional endpoints](https://soniox.com/docs/stt/data-residency#regional-endpoints) if you need data residency.
94​
95## Transcription Options
96​
97Per-request options are passed via `modelOptions`:
98​
99```typescript
100import { generateTranscription } from "@tanstack/ai";
101import { sonioxTranscription } from "@soniox/tanstack-ai-adapter";
102import { audio } from "./audio";
103​
104const result = await generateTranscription({
105 adapter: sonioxTranscription("stt-async-v3"),
106 audio,
107 modelOptions: {
108 languageHints: ["en", "es"],
109 enableLanguageIdentification: true,
110 enableSpeakerDiarization: true,
111 context: {
112 terms: ["Soniox", "TanStack"],
113 },
114 },
115});
116```
117​
118Available options:
119​
120- `languageHints` - Array of ISO language codes to bias recognition
121- `languageHintsStrict` - When true, rely more heavily on language hints (not supported by all models)
122- `enableLanguageIdentification` - Automatically detect spoken language
123- `enableSpeakerDiarization` - Identify and separate different speakers
124- `context` - Additional context to improve accuracy
125- `clientReferenceId` - Optional client-defined reference ID
126- `webhookUrl` - Webhook URL for completion notifications
127- `webhookAuthHeaderName` - Webhook authentication header name
128- `webhookAuthHeaderValue` - Webhook authentication header value
129- `translation` - Translation configuration
130​
131Check the [Soniox API reference](https://soniox.com/docs/stt/api-reference/transcriptions/create_transcription) for more details.
132​
133## Language Hints
134​
135Soniox automatically detects and transcribes speech in [60+ languages](https://soniox.com/docs/stt/concepts/supported-languages). When you know which languages are likely to appear in your audio, provide `languageHints` to improve accuracy by biasing recognition toward those languages.
136​
137Language hints do not restrict recognition. If you pass the TanStack `language` option, this adapter merges it into `languageHints`.
138​
139```typescript
140import { generateTranscription } from "@tanstack/ai";
141import { sonioxTranscription } from "@soniox/tanstack-ai-adapter";
142import { audio } from "./audio";
143​
144const result = await generateTranscription({
145 adapter: sonioxTranscription("stt-async-v3"),
146 audio,
147 modelOptions: {
148 languageHints: ["en", "es"],
149 },
150});
151```
152​
153For more details, see the [Soniox language hints documentation](https://soniox.com/docs/stt/concepts/language-hints).
154​
155## Context
156​
157Provide custom context to improve transcription and translation accuracy. Context helps the model understand your domain, recognize important terms, and apply custom vocabulary.
158​
159The `context` object supports four optional sections:
160​
161```typescript
162import { generateTranscription } from "@tanstack/ai";
163import { sonioxTranscription } from "@soniox/tanstack-ai-adapter";
164import { audio } from "./audio";
165​
166const result = await generateTranscription({
167 adapter: sonioxTranscription("stt-async-v3"),
168 audio,
169 modelOptions: {
170 context: {
171 general: [
172 { key: "domain", value: "Healthcare" },
173 { key: "topic", value: "Diabetes management consultation" },
174 { key: "doctor", value: "Dr. Martha Smith" },
175 ],
176 text: "The patient has a history of...",
177 terms: ["Celebrex", "Zyrtec", "Xanax"],
178 translationTerms: [
179 { source: "Mr. Smith", target: "Sr. Smith" },
180 { source: "MRI", target: "RM" },
181 ],
182 },
183 },
184});
185```
186​
187For more details, see the [Soniox context documentation](https://soniox.com/docs/stt/concepts/context).
188​
189## Translation
190​
191Configure translation for your transcriptions:
192​
193```typescript
194import { generateTranscription } from "@tanstack/ai";
195import { sonioxTranscription } from "@soniox/tanstack-ai-adapter";
196import { audio } from "./audio";
197​
198const result = await generateTranscription({
199 adapter: sonioxTranscription("stt-async-v3"),
200 audio,
201 modelOptions: {
202 translation: {
203 type: "one_way",
204 targetLanguage: "es",
205 },
206 },
207});
208```
209​
210For two-way translation:
211​
212```typescript
213import { generateTranscription } from "@tanstack/ai";
214import { sonioxTranscription } from "@soniox/tanstack-ai-adapter";
215import { audio } from "./audio";
216​
217const result = await generateTranscription({
218 adapter: sonioxTranscription("stt-async-v3"),
219 audio,
220 modelOptions: {
221 translation: {
222 type: "two_way",
223 languageA: "en",
224 languageB: "es",
225 },
226 },
227});
228```
229​
230When using translation, the API returns both transcription tokens and translation tokens. The `segments` array always includes only transcription tokens. To access translation tokens, use `providerMetadata` and filter by `translation_status === "translation"`.
231​
232### Accessing Raw Tokens
233​
234When using translation or working with multilingual audio, you may need access to raw tokens with per-token language information and translation status. The adapter attaches a non-standard `providerMetadata` field at runtime:
235​
236```typescript ignore
237// ignore: providerMetadata is a non-standard runtime extension not on TranscriptionResult;
238// accessing it requires a cast that cannot be expressed without `as`.
239const result = await generateTranscription({
240 adapter: sonioxTranscription("stt-async-v3"),
241 audio,
242 modelOptions: {
243 translation: { type: "one_way", targetLanguage: "es" },
244 },
245});
246​
247const rawTokens = (result as any).providerMetadata?.soniox?.tokens;
248​
249if (rawTokens) {
250 rawTokens.forEach((token) => {
251 // token.text - token text
252 // token.start_ms - start time in milliseconds
253 // token.end_ms - end time in milliseconds
254 // token.language - detected language for this token
255 // token.translation_status - translation status (if translation enabled)
256 // token.speaker - speaker identifier
257 // token.confidence - confidence score
258 });
260```
261​
262## Next Steps
263​
264- [Soniox Console](https://console.soniox.com) - Manage API keys and projects
265- [Soniox API docs](https://soniox.com/docs) - Complete Soniox API reference
266- [Transcription Guide](../media/transcription) - Learn about transcription in TanStack AI