跳转到内容

translation ​

translations的示例代码:(只需换成自己的key)
介绍
语音转文本API基于我们先进的开源large-v2 Whisper模型提供了两个端点,分别是“transcriptions”(转录)和“translations”(翻译)。它们可以用于:

将音频转录为与音频语言相同的文本。
将音频翻译并转录为英文。
目前,文件上传限制为25 MB,支持以下输入文件类型:mp3、mp4、mpeg、mpga、m4a、wav和webm。

import os
import openai
import requests
import time
import json
import time

API_SECRET_KEY = "你的Mishu获取的api_key";
BASE_URL = "https://mishu.one/v1"

# audio_transcriptions
def audio_transcriptions(file_name):
    openai.api_key = API_SECRET_KEY
    openai.api_base = BASE_URL
    audio_file = open(file_name, "rb")
    resp = openai.Audio.transcribe("whisper-1", audio_file)
    json_str = json.dumps(resp, ensure_ascii=False) #打出中文来
    print(json_str)

def translation(file_name):
    openai.api_key = API_SECRET_KEY
    openai.api_base = BASE_URL
    audio_file = open(file_name, "rb")
    resp = openai.Audio.translate("whisper-1", audio_file)
    json_str = json.dumps(resp, ensure_ascii=False) #打出中文来
    print(json_str)

if __name__ == '__main__':
    start = time.time();
    #audio_transcriptions("test.wav");
    translation("test.wav");
    end = time.time()
    print('本次处理时间(s): ', end - start)

Mishu · API 开发文档