Whisper语音转文字
whisper 模型接口说明
Section titled “whisper 模型接口说明”该接口基于 Whisper 模型实现语音转文本功能,支持常见音频格式。
- Whisper模型: OpenAI 开源的语音识别模型,支持多语言转写
- 音频格式: 支持 mp3、wav、m4a 等常见格式
POST https://api.4allapi.com/v1/audio/transcriptions
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 固定值 “whisper-1” |
| file | file | 是 | 要转写的音频文件 |
Authorization: Bearer sk-********************* # 替换为你的 API 令牌Python 调用示例
Section titled “Python 调用示例”import jsonimport requests
def voice_to_text(file_path): """ 语音转文本功能
参数: file_path: 音频文件路径
返回: 识别出的文本内容 """ url = "https://api.4allapi.com/v1/audio/transcriptions"
# 构造请求参数 payload = {"model": "whisper-1"} files = {"file": ("audio.mp3", open(file_path, "rb"))}
# 设置请求头(请替换为你的API密钥) headers = {"Authorization": "Bearer sk-***************************"} # 替换为你的 API 令牌
# 发送POST请求 response = requests.post(url, headers=headers, data=payload, files=files)
# 解析响应数据 data = json.loads(response.text)
# 返回识别结果 return data.get("text", "")
# 使用示例print(voice_to_text("audio.mp3")) # 替换为你的音频文件路径成功响应:
{ "text": "这是识别出的文本内容"}- 音频文件大小建议不超过25MB
- 支持中文、英文等多种语言
- 请妥善保管API密钥,不要泄露
4All API 页脚
Section titled “4All API 页脚”4All API · 一站式AI大模型API聚合平台 | 价格 | 联系我们
© 2025 4All API. All rights reserved.