语音识别
最后更新:2026-11-14
POSThttps://www.sagelib.com/audio/transcriptions
接收用户输入的语音文件/流式语音数据,把"声音信号"转换成"文字内容",适用于会议记录、字幕生成、信息提取等场景。
接口鉴权方式请参考:API接入与鉴权
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Authorization string |
鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN} |
*Content-Type string |
可选值:multipart/form-data multipart/form-data |
Body 参数
| 参数名称 | 描述 |
|---|---|
model string |
默认值:Per AI gateway configuration 模型名称 |
*file string |
语音输入文件,支持mp3/mp4/wav |
*language string |
可选值:ISO 639-1 standard, e.g. zh for Simplified Chinese 输入语音的语言 |
请求示例
curl -v 'https://www.sagelib.com/audio/transcriptions' \
-H "Authorization: Bearer ***" \
-F "file=@audio.mp3" \
-F "language=zh"
import requests
base_url = "https://www.sagelib.com"
api_key = "***"
url = f"https://www.sagelib.com/audio/transcriptions"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
"language": "zh"
}
files = {
"file": ("file.bin", open("file.bin", "rb"))
}
response = requests.post(url, headers=headers, data=data, files=files)
print(response.text)
import java.io.*;
import java.net.URI;
import java.net.http.*;
public class LlmStreamClient {
public static void main(String[] args) throws Exception {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/audio/transcriptions";
String boundary = "----Boundary" + System.currentTimeMillis();
String CRLF = "\r\n";
StringBuilder sb = new StringBuilder();
sb.append("--").append(boundary).append(CRLF);
sb.append("Content-Disposition: form-data; name=\"file\"").append(CRLF).append(CRLF);
sb.append("@audio.mp3").append(CRLF);
sb.append("--").append(boundary).append(CRLF);
sb.append("Content-Disposition: form-data; name=\"language\"").append(CRLF).append(CRLF);
sb.append("zh").append(CRLF);
sb.append("--").append(boundary).append("--").append(CRLF);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.header("Authorization", "Bearer " + apiKey)
.POST(HttpRequest.BodyPublishers.ofString(sb.toString()))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Status Code: " + response.statusCode());
System.out.println(response.body());
}
}
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/audio/transcriptions"
var buf bytes.Buffer
writer := multipart.NewWriter(&buf)
_ = writer.WriteField("file", "@audio.mp3")
_ = writer.WriteField("language", "zh")
writer.Close()
req, err := http.NewRequest("POST", url, &buf)
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", writer.FormDataContentType())
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request failed:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
响应参数
Body 参数
| 参数名称 | 描述 |
|---|---|
text string |
内容为识别出来的字符串,可能为空字符串 |
响应示例
{
"text": "xxx"
}
状态码
| HTTP状态码 | 描述 |
|---|---|
| 200 | 请求成功 |
| 401 | 访问被拒绝,拒绝原因见响应主体。可能的原因有:缺少Authorization请求头,token错误等。 |
| 403 | 访问被拒绝,原因见响应主体(如格式错误、参数缺失等) |
| 500 | 服务器内部错误,原因见响应主体 |