The parameters and API details for Paraformer non-real-time speech recognition HTTP API.
Prerequisites
You have activated the service and Obtain an API key. Please Configure API key as an environment variable instead of hardcoding it in your code to prevent security risks caused by code leakage.
Task submission interface
Basic information
| API endpoint description | Submits a speech recognition task. |
| URL | |
| Request method | POST |
| Request headers | |
| Message body | The following code shows a message body that contains all request parameters. You can omit optional fields as needed. |
Request parameters
Click to view a request example
Click to view a request example
| Parameter | Type | Default value | Required | Description |
|---|---|---|---|---|
| model | string | Yes | The name of the Paraformer model that is used for audio and video file transcription. For more information, see models. | |
| file_urls | array[string] | Yes | List of URLs for audio and video file transcription (HTTP/HTTPS). A single request supports only 1 URL.If your audio files are stored in OSS, the RESTful API supports temporary URLs that start with the oss:// prefix. | |
| vocabulary_id | string | No | Custom vocabulary ID. Supported by v2+ models with language configurations. Hotwords for this ID apply to current speech recognition. Disabled by default. For usage, see Custom hotwords. | |
| channel_id | array[integer] | [0] | No | Specifies the audio track indexes to recognize in a multi-track audio file. Indexes start from 0. For example, [0] means recognizing the first track, and [0, 1] means recognizing both the first and second tracks simultaneously. If this parameter is omitted, only the first track is processed by default. |
| disfluency_removal_enabled | boolean | false | No | Filters filler words. Disabled by default. |
| timestamp_alignment_enabled | boolean | false | No | Enables timestamp alignment feature. Disabled by default. |
| special_word_filter | string | No | Specifies sensitive words to process during speech recognition and supports setting different processing methods for different sensitive words.If this parameter is not provided, the system uses the built-in sensitive word filtering logic, and words matching the Alibaba Cloud Model Studio sensitive word list in the recognition results will be replaced with * of equal length.If this parameter is provided, the following sensitive word processing strategies can be implemented:
| |
| language_hints | array[string] | ["zh", "en"] | No | Specifies the language codes of the speech to be recognized.This parameter is only applicable to the paraformer-v2 model.Supported language codes:
|
| diarization_enabled | boolean | false | No | Automatic speaker diarization. Disabled by default.Only applicable to mono audio. Multi-channel audio does not support speaker diarization.When this feature is enabled, the recognition results will include a speaker_id field to distinguish different speakers.If speaker diarization is enabled, it is recommended that the audio duration does not exceed 2 hours, otherwise recognition may fail or time out. speaker_id, see Recognition result description. |
| speaker_count | integer | No | Reference value for speaker count (integer from 2 to 100, inclusive).Takes effect when diarization_enabled is true.Speaker count is automatically determined by default. Configuring this parameter assists the algorithm in targeting the specified count but does not guarantee exact output. |
Response parameters
Click to view a response example
Click to view a response example
Parameter | Type | Description |
|---|---|---|
task_status | string | The task status. |
task_id | string | The task ID. This ID is passed as a request parameter in the task query interface. |
Task query interface
Basic information
| API endpoint description | Queries the status and result of a speech recognition task. |
| URL | |
| Request method | GET |
| Request headers | |
| Message body | None. |
Request parameters
Click to view a request example
Click to view a request example
Parameter | Type | Default value | Required | Description |
|---|---|---|---|---|
task_id | string | - | Yes | Task ID required for query. Returned by the task submission interface. |
Response parameters
Click to view a response example
Click to view a response example
SUCCEEDED if any subtask succeeds. You must check the subtask_status field to determine the result of each subtask.- Normal example
- Exception example
Parameter | Type | Description |
|---|---|---|
task_id | string | The ID of the queried task. |
task_status | string | The status of the queried task. For tasks with multiple subtasks, task_status shows |
subtask_status | string | The subtask status. |
file_url | string | The URL of the file that is processed in the file transcription task. |
transcription_url | string | Link to obtain recognition result (valid 24 hours). After expiration, task queries and result downloads fail. Recognition result is saved as JSON. Download from this link or read directly via HTTP request. For JSON field details, see Recognition result description. |
Recognition result description
The recognition result is saved as a JSON file.
Click to view recognition result example
Click to view recognition result example
Parameter | Type | Description |
|---|---|---|
audio_format | string | The audio format of the source file. |
channels | array[integer] | The audio track index information of the source file. Returns [0] for mono audio, [0, 1] for dual-track audio, and so on. |
original_sampling_rate | integer | The sampling rate (Hz) of the audio in the source file. |
original_duration | integer | The original audio duration (ms) of the source file. |
channel_id | integer | The audio track index of the transcription result, starting from 0. |
content_duration | integer | The duration (ms) of content identified as speech in the audio track. The Paraformer speech recognition model service only transcribes and meters content identified as speech in the audio track, and bills accordingly. Non-speech content is neither metered nor billed. Typically, the speech content duration is shorter than the original audio duration. Since the determination of whether speech content exists is made by an AI model, there may be some deviation from the actual situation. |
transcript | string | The paragraph-level speech transcription result. |
sentences | array | The sentence-level speech transcription result. |
words | array | The word-level speech transcription result. |
begin_time | integer | The start timestamp (ms). |
end_time | integer | The end timestamp (ms). |
text | string | The speech transcription result. |
speaker_id | integer | The index of the current speaker, starting from 0, used to distinguish different speakers. This field is only displayed in the recognition results when speaker diarization is enabled. |
punctuation | string | The predicted punctuation after the word (if any). |
Complete example
Use built-in HTTP libraries to implement task submission and query requests. First submit the recognition task, and then repeatedly query until complete.
The following code provides an example in Python:
Error codes
If you encounter errors, see Error codes for troubleshooting.
If the issue persists, join the developer community to report the issue and provide the Request ID for further investigation.
When a task contains multiple subtasks, as long as any subtask succeeds, the overall task status is marked as SUCCEEDED. You need to check the subtask_status field to determine the result of each subtask.
Error response example:
More examples
For more examples, see our GitHub repository.
FAQ
Features
Q: Does it support Base64-encoded audio?
No. Base64-encoded audio is not supported. Only audio accessible via publicly accessible URLs is supported. Binary streams and direct local file recognition are not supported.
Q: How to provide audio files as publicly accessible URLs?
Generally, follow these steps (this provides a general approach; specifics vary by storage product. We recommend uploading audio to Alibaba Cloud OSS):
1. Choose a storage and hosting method
1. Choose a storage and hosting method
-
Object Storage Service (recommended):
- Use a cloud provider's object storage service (such as Alibaba Cloud OSS) to upload audio files to a bucket and set them to public access.
- Advantages: High availability, CDN acceleration support, easy management.
-
Web server:
- Place audio files on a web server that supports HTTP/HTTPS access (such as Nginx or Apache).
- Advantages: Suitable for small projects or local testing.
-
Content Delivery Network (CDN):
- Host audio files on a CDN and access them through the CDN-provided URL.
- Advantages: Accelerated file delivery, suitable for high-concurrency scenarios.
2. Upload audio files
2. Upload audio files
-
Object Storage Service:
- Log in to the cloud provider's console and create a bucket.
- Upload audio files and set file permissions to "public read" or generate temporary access links.
-
Web server:
- Place audio files in the server's designated directory (such as
/var/www/html/audio/). - Ensure files are accessible via HTTP/HTTPS.
- Place audio files in the server's designated directory (such as
3. Generate a publicly accessible URL
3. Generate a publicly accessible URL
-
Object Storage Service:
- After uploading, the system automatically generates a public access URL (typically in the format
https://<bucket-name>.<region>.aliyuncs.com/<file-name>). - If you need a more user-friendly domain, you can bind a custom domain and enable HTTPS.
- After uploading, the system automatically generates a public access URL (typically in the format
-
Web server:
- The file access URL is typically the server address plus the file path (such as
https://your-domain.com/audio/file.mp3).
- The file access URL is typically the server address plus the file path (such as
-
CDN:
- After configuring CDN acceleration, use the CDN-provided URL (such as
https://cdn.your-domain.com/audio/file.mp3).
- After configuring CDN acceleration, use the CDN-provided URL (such as
4. Verify URL accessibility
4. Verify URL accessibility
- Open the URL in a browser and check whether the audio file can be played.
- Use tools (such as
curlor Postman) to verify whether the URL returns a correct HTTP response (status code 200).
oss:// prefix are not supported.
When using the RESTful API, if audio files are stored in Alibaba Cloud OSS, temporary URLs with the oss:// prefix are supported:
- The temporary URL is valid for 48 hours and cannot be used after it expires. Do not use it in a production environment.
- The API for obtaining an upload credential is limited to 100 QPS and does not support scaling out. Do not use it in production environments, high-concurrency scenarios, or stress testing scenarios.
- For production environments, use a stable storage service such as OSS to ensure long-term file availability and avoid rate limiting issues.
Q: How long does it take to get recognition results?
After submission, the task enters a queued (PENDING) state. The queue time depends on the queue length and file duration and cannot be precisely estimated, but typically completes within a few minutes. Please wait patiently. Longer audio files require more processing time.
Troubleshooting
If you encounter an error, refer to the information in Error codes.
Q: What should I do if the recognition results are not synchronized with the audio playback?
Set timestamp_alignment_enabled request parameter to true. This synchronizes recognition results with audio playback.
Q: What should I do if I get an InvalidFile.DownloadFailed error after submitting a task?
Check whether the file URL contains spaces, Chinese characters, or other special characters. If the file name includes spaces (for example, "Meeting Recording Q1 2024.mp4"), URL-encode the file name by replacing spaces with %20 before passing it to the file_urls parameter.
Q: What do I do if the temporary public access URL of an OSS audio file is inaccessible?
Set X-DashScope-OssResourceResolve to enable in headers.
Not recommended.
The Java SDK and the Paraformer non-real-time speech recognition Python SDK don't support configuring headers.
Q: Unable to get results after continuous polling?
This may be due to rate limiting. Please wait patiently. If you need capacity expansion, join the developer community to apply.
Q: Why is there no recognition result (unable to recognize speech)?
- Check whether the audio meets the requirements (format, sampling rate).
- If you are using the
paraformer-v2model, check whether thelanguage_hintssetting is correct. - If none of the above resolves the issue, you can customize hot words to improve the recognition of specific words.