Question · Speech recognition
How do you use the Azure Speech-to-Text API?
To use the Azure Speech to text API, create a Speech resource, send your audio to its REST endpoint with your resource key in the Ocp-Apim-Subscription-Key header and a language in the URL, and read the transcript from the JSON reply. The short-audio REST call takes up to 60 seconds of audio, so longer recordings go to batch transcription, which Microsoft says can take up to 24 hours to finish at peak times.
Updated October 17, 20265 min read14 cited facts, each traced to its source
You use the Azure Speech to text API by creating a Speech resource in Azure, then calling one of two HTTP interfaces with your key. For a clip of up to 60 seconds 1, you send the audio in a single REST request. For a longer file, you submit a batch job that points at the audio and collect the transcript later. Both interfaces return text, and both need a language code. The steps below use the REST interfaces, because they work from any language with an HTTP client. For the wider comparison of providers, read the guide to speech-to-text APIs.
Create a Speech resource and copy its key first
Every call needs a resource key. Microsoft's quickstart starts with an Azure subscription, then a Speech resource that you create in the Azure portal, and then the option to view and manage keys once the resource is deployed ( Microsoft's Speech to text quickstart). The same resource gives you the region and the endpoint host, so keep all three together.
Microsoft also offers a free tier. The free (F0) tier of Azure AI Speech includes 5 audio hours a month of standard real-time transcription 2. That is enough to test the service, but it is not a production price.
Send a short WAV file to the REST endpoint in one request
The short-audio endpoint takes one recording and returns its transcript. Follow these steps:
- Convert your audio to WAV in PCM format, at the 16 kHz sample rate that the Content-Type header in step 4 uses. The short-audio REST API accepts a narrower list of formats than the Speech SDK 3, so check the list in Microsoft's reference before you send a file in another format.
- Build the URL with your resource name and the language. The endpoint has the form
https://YourResourceName.cognitiveservices.azure.com/stt/speech/recognition/conversation/cognitiveservices/v1?language=en-US. The language parameter is required, and leaving it out can cause a 4xx error 4. - Set the key header. Send your resource key in the Ocp-Apim-Subscription-Key header 5. Microsoft also accepts an authorization token, but the key is the simpler start.
- Send the audio. Set the content type to
audio/wav; codecs=audio/pcm; samplerate=16000and post the file body.
A minimal request looks like this:
curl -X POST "https://YourResourceName.cognitiveservices.azure.com/stt/speech/recognition/conversation/cognitiveservices/v1?language=en-US" \
-H "Ocp-Apim-Subscription-Key: YOUR_RESOURCE_KEY" \
-H "Content-Type: audio/wav; codecs=audio/pcm; samplerate=16000" \
--data-binary @sample.wav
Microsoft's own samples send the audio in chunks with chunked transfer encoding. The single upload above is a simplification that we did not run against a live resource, so test it on a short file first.
The reply is JSON with fields such as RecognitionStatus and DisplayText. The short-audio interface has limits you should plan around. It accepts no more than 60 seconds of audio in a request when the audio is sent directly 1. It returns only final results, so you get no partial text while someone is still speaking 6. For live captions, use the real-time SDK or the streaming interface instead.
The SDK is the usual route for applications. Microsoft's Python quickstart installs it with a single pip install azure-cognitiveservices-speech command 7.
For long recordings, submit a batch job
Batch transcription handles files longer than a minute, and many files at once. You put the audio where Azure can read it, send one submit request, and collect the results when they are ready. Microsoft's batch overview lists the options: upload your own files, or use existing audio through a public URI or a shared access signature (SAS) URI.
The submit request is a POST to the batch endpoint of your resource, with your key in the same header. Its JSON body names the files and the locale. Microsoft's example sends contentUrls with a list of public WAV links, a locale such as en-US, and a displayName. The request must set either contentUrls or contentContainerUrl 8. The reply includes links, and you read the transcript from the files link once the job completes.
Plan for waiting. Microsoft says that at peak hours a batch job might take up to 30 minutes to start and up to 24 hours to complete 9. Submitting jobs faster does not make them finish sooner 10, so a queue is the wrong fix for a deadline.
Do not use the short-audio endpoint for batch or custom speech. Microsoft's short-audio API does not support batch transcription or custom speech 11, so those jobs need the batch interface.
Tune recognition with a phrase list and set profanity behavior
A phrase list is the Azure version of custom vocabulary. You add names and terms, and set how strongly the recognizer favors them. The weight runs from 0.0, which disables the list, to 2.0, the maximum influence 12. Test the weight on your own terms, because a high weight can pull other words toward your list.
Profanity is masked by default. The setting replaces profanity with asterisks unless you change it 13.
Your audio is not stored for real-time requests
For real-time speech to text, Microsoft documents that audio is processed only in server memory and that no data is stored at rest 14. That statement covers the real-time service. Read the data terms for batch jobs and other products separately, because they can differ. The guide to voice data retention explains the questions to ask.
It depends on the audio length, the timing and your budget
- Short clips under a minute suit the REST call. A batch job for a single short clip adds waiting time for no gain.
- Long recordings suit batch, which accepts files your own app does not have to hold in memory, but the turnaround is measured in hours at peak.
- Live captions and voice agents need streaming, which is a different interface from the short-audio endpoint.
- Cost is the one thing this page does not give you. Microsoft's Azure AI Speech price page did not show the rates in the text we could read, so we do not quote an Azure price. Check the pricing page and calculate the hours you expect each month.
What to do
- Create a Speech resource and copy the key and region.
- Send a 30-second WAV file to the short-audio endpoint with the correct language code, and check the reply.
- If your files are longer than a minute, submit one batch job with a public or SAS URL, and time how long it takes.
- Measure word errors on five minutes of your own audio before you commit. The word error rate guide shows how to calculate it.
Related answers: how to use the Google Speech-to-Text API, how to use the ElevenLabs API, whether there is a free speech-to-text API and what IBM Watson Speech to Text is. The overview of speech recognition covers the technology underneath.
Evidence
Every number on this page, with where it comes from. Open a fact to see the exact words in its source.
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
Go deeper
Related questions
- Does Gemini have a speech-to-text API?
- How do you get a Google Speech-to-Text API key?
- How do you use the Google Speech-to-Text API?
- How much does the ElevenLabs speech-to-text API cost, and how do you use it?
- How much does the OpenAI speech-to-text API cost?
- Is ElevenLabs speech to text better than Whisper?
- Is Google Speech-to-Text free?
- Is there a free speech-to-text API?