Audio transcription and speech generation
Upload audio for transcription or generate speech and distinguish JSON from binary responses.
Prerequisites
Check the model's audio endpoints, input formats, and billing unit in the catalog. Transcription and speech generation usually require different models. Configure the key from the API overview. Examples use Bash.
Transcribe audio
Replace sample.wav with your file and select a transcription model. curl generates the multipart headers.
curl --fail-with-body 'https://gateway.irouter.io/v1/audio/transcriptions' \
-H "Authorization: Bearer $IROUTER_API_KEY" \
-F 'model=<model-id>' \
-F 'file=@sample.wav' \
-F 'response_format=json'For JSON output, read the text field; use the appropriate parser for other formats. Check file size, format, and the model's input constraints before uploading.
Generate speech
Replace <voice-id> with a voice supported by your selected speech model. This example requests an MP3 file.
curl --fail-with-body 'https://gateway.irouter.io/v1/audio/speech' \
-H "Authorization: Bearer $IROUTER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"model":"<model-id>","input":"Welcome to iRouter.","voice":"<voice-id>","response_format":"mp3"}' \
--output speech.mp3Check the HTTP status before using the output file; an error JSON file is not audio. Configure voice, speed, format, and text length for the selected model instead of reusing another model's voice names.
Usage and costs
Transcription and generation may use different billing units. Reconcile charges with the model page and usage records. Upload only necessary audio you are authorized to use, and store generated files under your application's data controls.