音频处理
语音识别与翻译
语音转文字 (STT) 和语音翻译
POST
/
v1
/
audio
/
transcriptions
curl https://www.qingbo.dev/v1/audio/transcriptions \
-H "Authorization: Bearer YOUR_API_KEY" \
-F file="@audio.mp3" \
-F model="whisper-1"
from openai import OpenAI
client = OpenAI(
base_url="https://www.qingbo.dev/v1",
api_key="YOUR_API_KEY"
)
with open("audio.mp3", "rb") as f:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=f
)
print(transcript.text)
import OpenAI from 'openai';
import fs from 'fs';
const client = new OpenAI({
baseURL: 'https://www.qingbo.dev/v1',
apiKey: 'YOUR_API_KEY'
});
const transcript = await client.audio.transcriptions.create({
model: 'whisper-1',
file: fs.createReadStream('audio.mp3')
});
console.log(transcript.text);
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
file, _ := os.Open("audio.mp3")
defer file.Close()
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, _ := writer.CreateFormFile("file", "audio.mp3")
io.Copy(part, file)
writer.WriteField("model", "whisper-1")
writer.Close()
req, _ := http.NewRequest("POST", "https://www.qingbo.dev/v1/audio/transcriptions", body)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", writer.FormDataContentType())
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}
import java.net.http.*;
import java.net.URI;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
String boundary = "----FormBoundary" + System.currentTimeMillis();
byte[] fileBytes = Files.readAllBytes(Path.of("audio.mp3"));
String body = "--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"file\"; filename=\"audio.mp3\"\r\n"
+ "Content-Type: audio/mpeg\r\n\r\n";
String fieldPart = "\r\n--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"model\"\r\n\r\nwhisper-1\r\n"
+ "--" + boundary + "--\r\n";
byte[] requestBody = new byte[body.getBytes().length + fileBytes.length + fieldPart.getBytes().length];
System.arraycopy(body.getBytes(), 0, requestBody, 0, body.getBytes().length);
System.arraycopy(fileBytes, 0, requestBody, body.getBytes().length, fileBytes.length);
System.arraycopy(fieldPart.getBytes(), 0, requestBody, body.getBytes().length + fileBytes.length, fieldPart.getBytes().length);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://www.qingbo.dev/v1/audio/transcriptions"))
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.POST(HttpRequest.BodyPublishers.ofByteArray(requestBody))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
{
"text": "欢迎使用 清波 API 语音识别服务。"
}
同步接口 — 请求完成后直接返回识别结果。
将音频转录为原始语言的文本。
将音频翻译为英文文本。参数与转录端点相同。
curl https://www.qingbo.dev/v1/audio/transcriptions \
-H "Authorization: Bearer YOUR_API_KEY" \
-F file="@audio.mp3" \
-F model="whisper-1"
from openai import OpenAI
client = OpenAI(
base_url="https://www.qingbo.dev/v1",
api_key="YOUR_API_KEY"
)
with open("audio.mp3", "rb") as f:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=f
)
print(transcript.text)
import OpenAI from 'openai';
import fs from 'fs';
const client = new OpenAI({
baseURL: 'https://www.qingbo.dev/v1',
apiKey: 'YOUR_API_KEY'
});
const transcript = await client.audio.transcriptions.create({
model: 'whisper-1',
file: fs.createReadStream('audio.mp3')
});
console.log(transcript.text);
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
file, _ := os.Open("audio.mp3")
defer file.Close()
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, _ := writer.CreateFormFile("file", "audio.mp3")
io.Copy(part, file)
writer.WriteField("model", "whisper-1")
writer.Close()
req, _ := http.NewRequest("POST", "https://www.qingbo.dev/v1/audio/transcriptions", body)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", writer.FormDataContentType())
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}
import java.net.http.*;
import java.net.URI;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
String boundary = "----FormBoundary" + System.currentTimeMillis();
byte[] fileBytes = Files.readAllBytes(Path.of("audio.mp3"));
String body = "--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"file\"; filename=\"audio.mp3\"\r\n"
+ "Content-Type: audio/mpeg\r\n\r\n";
String fieldPart = "\r\n--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"model\"\r\n\r\nwhisper-1\r\n"
+ "--" + boundary + "--\r\n";
byte[] requestBody = new byte[body.getBytes().length + fileBytes.length + fieldPart.getBytes().length];
System.arraycopy(body.getBytes(), 0, requestBody, 0, body.getBytes().length);
System.arraycopy(fileBytes, 0, requestBody, body.getBytes().length, fileBytes.length);
System.arraycopy(fieldPart.getBytes(), 0, requestBody, body.getBytes().length + fileBytes.length, fieldPart.getBytes().length);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://www.qingbo.dev/v1/audio/transcriptions"))
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.POST(HttpRequest.BodyPublishers.ofByteArray(requestBody))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
{
"text": "欢迎使用 清波 API 语音识别服务。"
}
可用模型
| 模型 ID | 说明 |
|---|---|
whisper-1 | OpenAI Whisper,支持多语言识别 |
两个端点
语音转文字
POST /v1/audio/transcriptions
语音翻译
POST /v1/audio/translations
请求参数
使用multipart/form-data 格式:
音频文件,支持 mp3、mp4、mpeg、mpga、m4a、wav、webm 格式
模型 ID:
whisper-1响应
识别或翻译后的文本内容
⌘I
curl https://www.qingbo.dev/v1/audio/transcriptions \
-H "Authorization: Bearer YOUR_API_KEY" \
-F file="@audio.mp3" \
-F model="whisper-1"
from openai import OpenAI
client = OpenAI(
base_url="https://www.qingbo.dev/v1",
api_key="YOUR_API_KEY"
)
with open("audio.mp3", "rb") as f:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=f
)
print(transcript.text)
import OpenAI from 'openai';
import fs from 'fs';
const client = new OpenAI({
baseURL: 'https://www.qingbo.dev/v1',
apiKey: 'YOUR_API_KEY'
});
const transcript = await client.audio.transcriptions.create({
model: 'whisper-1',
file: fs.createReadStream('audio.mp3')
});
console.log(transcript.text);
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
file, _ := os.Open("audio.mp3")
defer file.Close()
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, _ := writer.CreateFormFile("file", "audio.mp3")
io.Copy(part, file)
writer.WriteField("model", "whisper-1")
writer.Close()
req, _ := http.NewRequest("POST", "https://www.qingbo.dev/v1/audio/transcriptions", body)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", writer.FormDataContentType())
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}
import java.net.http.*;
import java.net.URI;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
String boundary = "----FormBoundary" + System.currentTimeMillis();
byte[] fileBytes = Files.readAllBytes(Path.of("audio.mp3"));
String body = "--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"file\"; filename=\"audio.mp3\"\r\n"
+ "Content-Type: audio/mpeg\r\n\r\n";
String fieldPart = "\r\n--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"model\"\r\n\r\nwhisper-1\r\n"
+ "--" + boundary + "--\r\n";
byte[] requestBody = new byte[body.getBytes().length + fileBytes.length + fieldPart.getBytes().length];
System.arraycopy(body.getBytes(), 0, requestBody, 0, body.getBytes().length);
System.arraycopy(fileBytes, 0, requestBody, body.getBytes().length, fileBytes.length);
System.arraycopy(fieldPart.getBytes(), 0, requestBody, body.getBytes().length + fileBytes.length, fieldPart.getBytes().length);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://www.qingbo.dev/v1/audio/transcriptions"))
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.POST(HttpRequest.BodyPublishers.ofByteArray(requestBody))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
{
"text": "欢迎使用 清波 API 语音识别服务。"
}