Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

Transcribe audio with Whisper

Turn an audio file into text with Whisper Large, then read per-segment timestamps and confidence scores.

  • An API key from the aixplain app and credits in your workspace.
  • pip install aixplain
  • An audio file, or a public URL to one.

Whisper detects the spoken language on its own, so the same call works for English, Arabic and the other languages it supports.

note

Whisper Large costs 0.0018 credits per minute of audio.

Upload a local file​

The model reads audio from a URL. Upload your file to temporary aixplain storage to get a signed URL.

from aixplain import Aixplain
from aixplain.v2 import FileUploader

aix = Aixplain(api_key="YOUR_API_KEY")

audio_url = FileUploader(api_key=aix.api_key).upload(
file_path="greeting.wav",
is_temp=True,
return_download_link=True,
)

You now have audio_url, a signed URL the model can fetch.

Transcribe the file​

model = aix.Model.get("66311fda6eb563279c574b71") # Whisper Large

result = model.run(
source_audio=audio_url,
sourcelanguage="en",
options={"includeRawData": True},
)

print(result.status)
print(result.data)
print(result.used_credits, result.run_time)
Show output

The transcript is in result.data. The SDK requires sourcelanguage, but its value does not change detection: this Arabic audio was transcribed with "en".

Read timestamps and confidence​

options={"includeRawData": True} returns Whisper's full response, with the detected language, the duration and each segment.

raw = result._raw_data["rawData"]
print(raw["language"], raw["duration"])

for seg in raw["segments"][:3]:
print(f"[{seg['start']:.2f}s - {seg['end']:.2f}s] {seg['text'].strip()}")
Show output

Each segment also has avg_logprob, a confidence proxy, and no_speech_prob, the likelihood that the segment is silence.

Transcribe a public URL with REST​

When the audio is already at a public URL, call the execute endpoint directly from any language.

import requests

MODEL_ID = "66311fda6eb563279c574b71"

response = requests.post(
f"https://models.aixplain.com/api/v2/execute/{MODEL_ID}",
headers={"Content-Type": "application/json", "x-api-key": "YOUR_API_KEY"},
json={
"source_audio": "https://dare.wisc.edu/wp-content/uploads/sites/1051/2008/04/Arthur.mp3",
"options": {"includeRawData": True},
},
)
data = response.json()

print(data["status"], data["rawData"]["language"], data["rawData"]["duration"])
print(len(data["rawData"]["segments"]), "segments")
print(data["data"][:120])
Show output

The same request with curl:

curl --location 'https://models.aixplain.com/api/v2/execute/66311fda6eb563279c574b71' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY' \
--data '{
"source_audio": "https://dare.wisc.edu/wp-content/uploads/sites/1051/2008/04/Arthur.mp3",
"options": {"includeRawData": true}
}'

The provider downloads the audio, so the URL must be public or signed. An unreachable URL fails with err.invalid_input_data_or_input_url.

Reference​

ParameterTypeDefaultDescription
source_audiostrrequiredPublic or signed URL to the audio, such as the URL from FileUploader.
sourcelanguagestrrequired in the SDKAny language code. Whisper detects the actual language. Optional over REST.
options.includeRawDataboolFalseReturn the full Whisper response in rawData, with segments, tokens and log-probabilities.

Next steps​

  • Models: run any Marketplace model, with streaming and async calls.
  • REST API: upload files and call models from any language.
  • Tutorials: more step-by-step builds.