兼容 OpenAI 的语音合成与转写
一个 SDK,两个接口#
按 OpenAI SDK 写法编写的语音合成和转写调用,已指向 Paxa,并使用 Paxa 的密钥、模型 ID 和音色。字段对照取自 API 文档。
import os from openai import OpenAI client = OpenAI( base_url="https://api.paxalabs.com/v1", api_key=os.environ["PAXA_API_KEY"], ) with client.audio.speech.with_streaming_response.create( model="paxa-tts-flash-v2", voice="khanomkrok", input="สวัสดีครับ ยินดีต้อนรับสู่ Paxa Labs", ) as response: response.stream_to_file("speech.mp3")
import { writeFile } from "node:fs/promises"; import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.paxalabs.com/v1", apiKey: process.env.PAXA_API_KEY, }); const response = await client.audio.speech.create({ model: "paxa-tts-flash-v2", voice: "khanomkrok", input: "สวัสดีครับ ยินดีต้อนรับสู่ Paxa Labs", }); await writeFile("speech.mp3", Buffer.from(await response.arrayBuffer()));
curl -X POST https://api.paxalabs.com/v1/audio/speech \ -H "Authorization: Bearer $PAXA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "paxa-tts-flash-v2", "input": "สวัสดีครับ ยินดีต้อนรับสู่ Paxa Labs", "voice": "khanomkrok" }' \ --output speech.mp3
Field mapping
| Field | Behavior |
|---|---|
| model | Required, same as on /v1/tts. A Paxa model id, for example paxa-tts-flash-v2. OpenAI's tts-1, tts-1-hd, gpt-4o-mini-tts, gpt-4o-mini-tts-2025-03-20, gpt-4o-mini-tts-2025-12-15 also work and run on paxa-tts-flash-v2. |
| input | The text to synthesize. Same limits, pricing, direction tags, and emotion tags on paxa-tts-flash-v1 as text on /v1/tts. |
| voice | The voice id from GET /v1/voices, for example "khanomkrok"; case is ignored, as for voice on /v1/tts. This endpoint also takes OpenAI's voice names, such as alloy, mapped to Paxa voices, and the x-voice-id response header names the voice that spoke. |
| response_format | mp3 (the default), opus, wav, pcm (16-bit little-endian mono at 24 kHz, as OpenAI's, unless sample_rate names another rate), mulaw, or alaw, as format on /v1/tts. Paxa TTS Flash answers mulaw and alaw with unsupported_format, and other OpenAI formats answer 400. |
| sample_rate | A Paxa extension, read for pcm and wav as on /v1/tts and ignored with other formats, though any value must be one of Paxa TTS Flash v2's rates. It sets their rate in Hz, where Paxa TTS Flash v2 serves 8000, 16000, 22050, 24000, 32000, 44100, 48000 and Paxa TTS Flash only 24000. Set it when the platform playing the audio expects a fixed rate. |
| temperature | A Paxa extension, read as on /v1/tts: how much the reading varies from one request to the next, from 0 to 2 on Paxa TTS Flash v2. Temperature covers it. |
| stream | Defaults to true, matching OpenAI delivery. Set false for a complete body with a content-length. |
Transcription
| Field | Behavior |
|---|---|
| file | The recording as a file part, in any of 7 containers; the format and the length come from the bytes. Same ceilings and pricing as audio on /v1/stt. |
| model | Required. A Paxa model id, for example paxa-stt-lite-v1-preview. OpenAI's whisper-1, gpt-4o-transcribe, gpt-4o-mini-transcribe, gpt-4o-mini-transcribe-2025-03-20, gpt-4o-mini-transcribe-2025-12-15 also work and run on paxa-stt-lite-v1-preview. |
| language | A BCP 47 hint, the same field as on /v1/stt. Omitted, the model detects the language itself. |
| response_format | json (the default), verbose_json, text, srt, or vtt. verbose_json adds the duration, the segments, and the words when timestamp_granularities names word. |
三步完成切换#
SDK 和原有调用保持不变,模型名和音色名也照常可用。两个接口共用同一个 base URL 和同一个密钥。
把 base URL 指向 Paxa
把 SDK 的 base URL 设为 https://api.paxalabs.com/v1,SDK 随即调用 Paxa 的 /v1/audio/speech 和 /v1/audio/transcriptions。
更换密钥
用控制台里的 Paxa API 密钥替换 OpenAI 密钥,并保存在 PAXA_API_KEY 这类环境变量中。
按需指定 Paxa 模型
语音合成可以沿用 OpenAI 的模型名和音色名,它们在 paxa-tts-flash-v2 上运行;也可以把 model 设为 paxa-tts-flash-v2 或 paxa-tts-flash-v1,并使用该模型提供的音色 ID。转写可以沿用 OpenAI 的模型名,也可以把 model 设为 paxa-stt-lite-v1-preview,该模型是研究预览版。
Paxa TTS Flash v2 标价为每百万字符 $10。Paxa STT Lite 标价为每小时音频 $0.50,按毫秒计费。
常见问题#
语音合成接口支持哪些参数?
默认以流式返回 mp3,也可以选 opus、wav、pcm、mulaw 或 alaw,aac 和 flac 会返回 400。把 stream 设为 false 可取回完整文件。speed 在模型支持的范围内生效,超出范围会返回 400。language 字段会被忽略,所有请求都按 auto 读取。
转写接口支持哪些参数?
录音以 multipart 文件上传,支持 7 种音频格式,最长 60 分钟、最大 25 MiB。默认返回 json,也可以选 verbose_json、text、srt 或 vtt。language 是可选的提示,不填时模型会自行识别语言。Paxa STT Lite 目前是研究预览版。
哪些 OpenAI 字段会被忽略?
语音合成接口忽略 instructions,转写接口忽略 prompt 和 temperature,并在使用 verbose_json 时读取 timestamp_granularities。带有这些字段的调用照常运行。转写请求把 stream 设为 true 会返回 400。时间戳和说话人轮次等 Paxa 自有选项,在 /v1/tts 和 /v1/stt 上提供。
从免费积分开始
使用 Google、GitHub 或 Hugging Face 登录,即可用 100 一次性免费积分处理您自己的文本。