语音转文本

Portkey 的 AI 网关支持像 OpenAI 的 Whisper 这样的 STT 模型。

转录与翻译使用

Portkey 支持 TranscriptionTranslation 方法用于 STT 模型,并遵循 OpenAI 签名,您可以将文件(格式为 flacmp3mp4mpegmpgam4aoggwavwebm)作为 API 请求的一部分发送。

示例:

import fs from "fs";
import OpenAI from "openai";
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'

const openai = new OpenAI({
  baseURL: PORTKEY_GATEWAY_URL,
  defaultHeaders: createHeaders({
    apiKey: "PORTKEY_API_KEY",
    virtualKey: "OPENAI_VIRTUAL_KEY"
  })
});

// Transcription

async function transcribe() {
  const transcription = await openai.audio.transcriptions.create({
    file: fs.createReadStream("/path/to/file.mp3"),
    model: "whisper-1",
  });

  console.log(transcription.text);
}
transcribe();

// Translation

async function translate() {
    const translation = await openai.audio.translations.create({
        file: fs.createReadStream("/path/to/file.mp3"),
        model: "whisper-1",
    });
    console.log(translation.text);
}
translate();

完成后,请求将记录在日志 UI 中,您可以查看转录或翻译的文本,以及产生的费用和延迟。

支持的提供商和模型

以下提供商支持语音转文本,更多提供商将很快添加。请提出请求PR以将模型或提供商添加到AI网关。

提供商
模型
功能

whisper-1

转录 翻译

Last updated