Skip to content

Commit c297db5

Browse files
Add speech_models parameter to code examples in language pages
Co-Authored-By: Lee Vaughn <dlvprogramming@gmail.com>
1 parent 5197442 commit c297db5

File tree

2 files changed

+69
-30
lines changed

2 files changed

+69
-30
lines changed

fern/pages/02-speech-to-text/pre-recorded-audio/automatic-language-detection.mdx

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,26 @@ Identify the dominant language spoken in an audio file and use it during the tra
141141

142142
<CodeBlocks>
143143

144-
```python title="Python SDK" for="python-sdk" highlight={8} maxLines=15
144+
```python title="Python SDK" for="python-sdk" highlight={16} maxLines=15
145145
import assemblyai as aai
146146

147147
aai.settings.api_key = "<YOUR_API_KEY>"
148148

149149
# audio_file = "./local_file.mp3"
150150
audio_file = "https://assembly.ai/wildfires.mp3"
151151

152-
config = aai.TranscriptionConfig(language_detection=True)
152+
config = aai.TranscriptionConfig(
153+
speech_models=["universal-3-pro", "universal-2"],
154+
language_detection=True
155+
)
153156

154157
transcript = aai.Transcriber(config=config).transcribe(audio_file)
155158

156159
print(transcript.text)
157160
print(transcript.json_response["language_code"])
158161
```
159162

160-
```python title="Python" for="python" highlight={19} maxLines=15
163+
```python title="Python" for="python" highlight={21} maxLines=15
161164
import requests
162165
import time
163166

@@ -176,6 +179,7 @@ upload_url = response.json()["upload_url"]
176179

177180
data = {
178181
"audio_url": upload_url, # You can also use a URL to an audio or video file on the web
182+
"speech_models": ["universal-3-pro", "universal-2"],
179183
"language_detection": True,
180184
}
181185

@@ -202,7 +206,7 @@ while True:
202206

203207
```
204208

205-
```javascript title="JavaScript SDK" for="javascript-sdk" highlight={12} maxLines=15
209+
```javascript title="JavaScript SDK" for="javascript-sdk" highlight={14} maxLines=15
206210
import { AssemblyAI } from "assemblyai";
207211

208212
const client = new AssemblyAI({
@@ -214,6 +218,7 @@ const audioFile = "https://assembly.ai/wildfires.mp3";
214218

215219
const params = {
216220
audio: audioFile,
221+
speech_models: ["universal-3-pro", "universal-2"],
217222
language_detection: true,
218223
};
219224

@@ -227,7 +232,7 @@ const run = async () => {
227232
run();
228233
```
229234

230-
```javascript title="JavaScript" for="javascript" highlight={19} maxLines=15
235+
```javascript title="JavaScript" for="javascript" highlight={21} maxLines=15
231236
import axios from "axios";
232237
import fs from "fs-extra";
233238

@@ -246,6 +251,7 @@ const uploadUrl = uploadResponse.data.upload_url;
246251

247252
const data = {
248253
audio_url: uploadUrl, // You can also use a URL to an audio or video file on the web
254+
speech_models: ["universal-3-pro", "universal-2"],
249255
language_detection: true,
250256
};
251257

@@ -284,7 +290,7 @@ If you're confident the audio is in one of a few languages, provide that list vi
284290

285291
<CodeBlocks>
286292

287-
```python title="Python SDK" for="python-sdk" highlight={9} maxLines=15
293+
```python title="Python SDK" for="python-sdk" highlight={15} maxLines=15
288294
import assemblyai as aai
289295

290296
aai.settings.api_key = "<YOUR_API_KEY>"
@@ -297,15 +303,19 @@ options = aai.LanguageDetectionOptions(
297303
fallback_language="auto"
298304
)
299305

300-
config = aai.TranscriptionConfig(language_detection=True, language_detection_options=options)
306+
config = aai.TranscriptionConfig(
307+
speech_models=["universal-3-pro", "universal-2"],
308+
language_detection=True,
309+
language_detection_options=options
310+
)
301311

302312
transcript = aai.Transcriber(config=config).transcribe(audio_file)
303313

304314
print(transcript.text)
305315
print(transcript.json_response["language_code"])
306316
```
307317

308-
```python title="Python" for="python" highlight={21} maxLines=15
318+
```python title="Python" for="python" highlight={23} maxLines=15
309319
import requests
310320
import time
311321

@@ -324,6 +334,7 @@ upload_url = response.json()["upload_url"]
324334

325335
data = {
326336
"audio_url": upload_url, # You can also use a URL to an audio or video file on the web
337+
"speech_models": ["universal-3-pro", "universal-2"],
327338
"language_detection": True,
328339
"language_detection_options": {
329340
"expected_languages": ["en", "es", "fr", "de"],
@@ -354,7 +365,7 @@ while True:
354365

355366
```
356367

357-
```javascript title="JavaScript SDK" for="javascript-sdk" highlight={14} maxLines=15
368+
```javascript title="JavaScript SDK" for="javascript-sdk" highlight={16} maxLines=15
358369
import { AssemblyAI } from "assemblyai";
359370

360371
const client = new AssemblyAI({
@@ -366,6 +377,7 @@ const audioFile = "https://assembly.ai/wildfires.mp3";
366377

367378
const params = {
368379
audio: audioFile,
380+
speech_models: ["universal-3-pro", "universal-2"],
369381
language_detection: true,
370382
language_detection_options: {
371383
expected_languages: ["en", "es", "fr", "de"],
@@ -383,7 +395,7 @@ const run = async () => {
383395
run();
384396
```
385397

386-
```javascript title="JavaScript" for="javascript" highlight={21} maxLines=15
398+
```javascript title="JavaScript" for="javascript" highlight={23} maxLines=15
387399
import axios from "axios";
388400
import fs from "fs-extra";
389401

@@ -402,6 +414,7 @@ const uploadUrl = uploadResponse.data.upload_url;
402414

403415
const data = {
404416
audio_url: uploadUrl, // You can also use a URL to an audio or video file on the web
417+
speech_models: ["universal-3-pro", "universal-2"],
405418
language_detection: true,
406419
language_detection_options: {
407420
expected_languages: ["en", "es", "fr", "de"],
@@ -445,7 +458,7 @@ Control what language transcription should fall back to when detection cannot co
445458

446459
<CodeBlocks>
447460

448-
```python title="Python SDK" for="python-sdk" highlight={10} maxLines=15
461+
```python title="Python SDK" for="python-sdk" highlight={16} maxLines=15
449462
import assemblyai as aai
450463

451464
aai.settings.api_key = "<YOUR_API_KEY>"
@@ -458,15 +471,19 @@ options = aai.LanguageDetectionOptions(
458471
fallback_language="auto"
459472
)
460473

461-
config = aai.TranscriptionConfig(language_detection=True, language_detection_options=options)
474+
config = aai.TranscriptionConfig(
475+
speech_models=["universal-3-pro", "universal-2"],
476+
language_detection=True,
477+
language_detection_options=options
478+
)
462479

463480
transcript = aai.Transcriber(config=config).transcribe(audio_file)
464481

465482
print(transcript.text)
466483
print(transcript.json_response["language_code"])
467484
```
468485

469-
```python title="Python" for="python" highlight={22} maxLines=15
486+
```python title="Python" for="python" highlight={23} maxLines=15
470487
import requests
471488
import time
472489

@@ -485,6 +502,7 @@ upload_url = response.json()["upload_url"]
485502

486503
data = {
487504
"audio_url": upload_url, # You can also use a URL to an audio or video file on the web
505+
"speech_models": ["universal-3-pro", "universal-2"],
488506
"language_detection": True,
489507
"language_detection_options": {
490508
"expected_languages": ["en", "es", "fr", "de"],
@@ -515,7 +533,7 @@ while True:
515533

516534
```
517535

518-
```javascript title="JavaScript SDK" for="javascript-sdk" highlight={15} maxLines=15
536+
```javascript title="JavaScript SDK" for="javascript-sdk" highlight={16} maxLines=15
519537
import { AssemblyAI } from "assemblyai";
520538

521539
const client = new AssemblyAI({
@@ -527,6 +545,7 @@ const audioFile = "https://assembly.ai/wildfires.mp3";
527545

528546
const params = {
529547
audio: audioFile,
548+
speech_models: ["universal-3-pro", "universal-2"],
530549
language_detection: true,
531550
language_detection_options: {
532551
expected_languages: ["en", "es", "fr", "de"],
@@ -544,7 +563,7 @@ const run = async () => {
544563
run();
545564
```
546565

547-
```javascript title="JavaScript" for="javascript" highlight={22} maxLines=15
566+
```javascript title="JavaScript" for="javascript" highlight={23} maxLines=15
548567
import axios from "axios";
549568
import fs from "fs-extra";
550569

@@ -563,6 +582,7 @@ const uploadUrl = uploadResponse.data.upload_url;
563582

564583
const data = {
565584
audio_url: uploadUrl, // You can also use a URL to an audio or video file on the web
585+
speech_models: ["universal-3-pro", "universal-2"],
566586
language_detection: true,
567587
language_detection_options: {
568588
expected_languages: ["en", "es", "fr", "de"],
@@ -602,23 +622,26 @@ If language detection is enabled, the API returns a confidence score for the det
602622

603623
<CodeBlocks>
604624

605-
```python title="Python SDK" for="python-sdk" highlight={8,13} maxLines=15
625+
```python title="Python SDK" for="python-sdk" highlight={10,16} maxLines=15
606626
import assemblyai as aai
607627

608628
aai.settings.api_key = "<YOUR_API_KEY>"
609629

610630
# audio_file = "./local_file.mp3"
611631
audio_file = "https://assembly.ai/wildfires.mp3"
612632

613-
config = aai.TranscriptionConfig(language_detection=True)
633+
config = aai.TranscriptionConfig(
634+
speech_models=["universal-3-pro", "universal-2"],
635+
language_detection=True
636+
)
614637

615638
transcript = aai.Transcriber(config=config).transcribe(audio_file)
616639

617640
print(transcript.text)
618641
print(transcript.json_response["language_confidence"])
619642
```
620643

621-
```python title="Python" for="python" highlight={33} maxLines=15
644+
```python title="Python" for="python" highlight={34} maxLines=15
622645
import requests
623646
import time
624647

@@ -637,6 +660,7 @@ upload_url = response.json()["upload_url"]
637660

638661
data = {
639662
"audio_url": upload_url, # You can also use a URL to an audio or video file on the web
663+
"speech_models": ["universal-3-pro", "universal-2"],
640664
"language_detection": True
641665
}
642666

@@ -663,7 +687,7 @@ while True:
663687

664688
```
665689

666-
```javascript title="JavaScript SDK" for="javascript-sdk" highlight={19} maxLines=15
690+
```javascript title="JavaScript SDK" for="javascript-sdk" highlight={20} maxLines=15
667691
import { AssemblyAI } from "assemblyai";
668692

669693
const client = new AssemblyAI({
@@ -675,6 +699,7 @@ const audioFile = "https://assembly.ai/wildfires.mp3";
675699

676700
const params = {
677701
audio: audioFile,
702+
speech_models: ["universal-3-pro", "universal-2"],
678703
language_detection: true,
679704
};
680705

@@ -688,7 +713,7 @@ const run = async () => {
688713
run();
689714
```
690715

691-
```javascript title="JavaScript" for="javascript" highlight={36} maxLines=15
716+
```javascript title="JavaScript" for="javascript" highlight={37} maxLines=15
692717
import axios from "axios";
693718
import fs from "fs-extra";
694719

@@ -707,6 +732,7 @@ const uploadUrl = uploadResponse.data.upload_url;
707732

708733
const data = {
709734
audio_url: uploadUrl, // You can also use a URL to an audio or video file on the web
735+
speech_models: ["universal-3-pro", "universal-2"],
710736
language_detection: true,
711737
};
712738

@@ -743,15 +769,19 @@ if the language confidence is below this threshold. Valid values are in the rang
743769

744770
<CodeBlocks>
745771

746-
```python title="Python SDK" for="python-sdk" highlight={8,13} maxLines=15
772+
```python title="Python SDK" for="python-sdk" highlight={10,16} maxLines=15
747773
import assemblyai as aai
748774

749775
aai.settings.api_key = "<YOUR_API_KEY>"
750776

751777
# audio_file = "./local_file.mp3"
752778
audio_file = "https://assembly.ai/wildfires.mp3"
753779

754-
config = aai.TranscriptionConfig(language_detection=True, language_confidence_threshold=0.8)
780+
config = aai.TranscriptionConfig(
781+
speech_models=["universal-3-pro", "universal-2"],
782+
language_detection=True,
783+
language_confidence_threshold=0.8
784+
)
755785

756786
transcript = aai.Transcriber(config=config).transcribe(audio_file)
757787

@@ -762,7 +792,7 @@ else:
762792
print(transcript.text)
763793
```
764794

765-
```python title="Python" for="python" highlight={20} maxLines=15
795+
```python title="Python" for="python" highlight={21} maxLines=15
766796
import requests
767797
import time
768798

@@ -781,6 +811,7 @@ upload_url = response.json()["upload_url"]
781811

782812
data = {
783813
"audio_url": upload_url, # You can also use a URL to an audio or video file on the web
814+
"speech_models": ["universal-3-pro", "universal-2"],
784815
"language_detection": True,
785816
"language_confidence_threshold": 0.8
786817
}
@@ -807,7 +838,7 @@ while True:
807838

808839
```
809840

810-
```javascript title="JavaScript SDK" for="javascript-sdk" highlight={13} maxLines=15
841+
```javascript title="JavaScript SDK" for="javascript-sdk" highlight={14} maxLines=15
811842
import { AssemblyAI } from "assemblyai";
812843

813844
const client = new AssemblyAI({
@@ -819,6 +850,7 @@ const audioFile = "https://assembly.ai/wildfires.mp3";
819850

820851
const params = {
821852
audio: audioFile,
853+
speech_models: ["universal-3-pro", "universal-2"],
822854
language_detection: true,
823855
language_confidence_threshold: 0.8,
824856
};
@@ -837,7 +869,7 @@ const run = async () => {
837869
run();
838870
```
839871

840-
```javascript title="JavaScript" for="javascript" highlight={20} maxLines=15
872+
```javascript title="JavaScript" for="javascript" highlight={21} maxLines=15
841873
import axios from "axios";
842874
import fs from "fs-extra";
843875

@@ -856,6 +888,7 @@ const uploadUrl = uploadResponse.data.upload_url;
856888

857889
const data = {
858890
audio_url: uploadUrl, // You can also use a URL to an audio or video file on the web
891+
speech_models: ["universal-3-pro", "universal-2"],
859892
language_detection: true,
860893
language_confidence_threshold: 0.8,
861894
};

0 commit comments

Comments
 (0)