Speech Recognition API
Version requirement: Pro and above
Introduction
The speech recognition API converts audio files to text content, supporting multiple languages.
Online API testing: API Debug Console
API Definition
Endpoint
POST https://api.linkai.cloud/v1/audio/transcriptions
Request Headers
Parameter | Value | Description |
---|---|---|
Authorization | Bearer YOUR_API_KEY | Create an API Key following Authentication |
Content-Type | multipart/form-data | Indicates form data format for uploading audio files |
Request Body
Parameter | Type | Required | Description |
---|---|---|---|
file | file | Yes | Audio file, supports mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm, flac, amr formats |
Response
The text field contains the recognized text content:
{
"text": "Hello, I need some help"
}
Error Handling
When an error occurs, the API returns the following structure:
{
"success": false,
"code": 408,
"message": "No API access permission for current version",
"data": null
}
Determine the error type based on the HTTP status code and error message:
HTTP Status Code | Description |
---|---|
400 | Invalid request format |
401 | Authentication failed, please check if your API Key is correct |
402 | Agent does not exist, please check if the app_code parameter is correct |
403 | No access permission, for private Agents, only the creator account can call |
406 | Insufficient account credits |
408 | No API access permission, this API supports Pro version and above |
409 | Content moderation failed, sensitive content may exist in the question, answer, or knowledge base |
503 | API call exception, please contact customer service |
Example Code
1. CURL Request
curl https://api.linkai.cloud/v1/audio/transcriptions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F file="@/path/to/file/audio.mp3"
Note: Replace YOUR_API_KEY
with your created API Key, and provide the local path to your audio file in the file
parameter.
2. Python Code
import requests
file_path = '/path/to/file/audio.mp3' # Replace with the path to your audio file
url = 'https://api.linkai.cloud/v1/audio/transcriptions'
headers = {
'Authorization': f'Bearer YOUR_API_KEY'
}
files = {
'file': open(file_path, 'rb')
}
res = requests.post(url, headers=headers, files=files)
if res.status_code == 200:
res_json = res.json()
reply_text = res_json.get("text")
print(f"text={reply_text}")
else:
error = res.json()
print(f"Request error, status code={error.get('code')}, error message={error.get('message')}")
Note: Replace YOUR_API_KEY
with your created API Key, and provide the local path to your audio file in the file_path
variable.
Authentication
API calls are authenticated using API Keys. Before making calls, you need to create an API Key following Authentication