# 文字转语音

简介 Afarensis TTS API 利用先进的文本到语音转换技术，提供了一个功能丰富的语音终结点。它配备了六种内置声音，支持各种用途，包括叙述博客文章、制作多语言语音音频和实时音频输出。

快速入门 基本请求 from pathlib import Path from afarensis import AfarensisAPI

client = AfarensisAPI()

speech\_file\_path = Path(**file**).parent / "speech.mp3" response = client.audio.speech.create( model="tts-1", voice="alloy", input="Today is a wonderful day to build something people love!" )

response.stream\_to\_file(speech\_file\_path) 默认情况下，API 生成 MP3 格式的语音音频文件，但支持其他格式。

语音选项 Afarensis 提供多种声音选择，如 "alloy"、"echo"、"fable"、"onyx"、"nova" 和 "shimmer"，以匹配不同语气和听众需求。

音频质量 标准模型 ("tts-1")：提供最快响应时间，适合实时应用，但音质可能低于 "tts-1-hd"。 高质量模型 ("tts-1-hd")：在保持较低延迟的同时提供更高的音质。 支持的输出格式 除 MP3 外，还支持 Opus、AAC、FLAC 和 WAV 格式，以满足不同应用需求。

语言支持 虽然当前声音优化针对英语，但 Afarensis TTS 模型支持多种语言，性能良好。

流式传输实时音频 from afarensis import AfarensisAPI

client = AfarensisAPI()

response = client.audio.speech.create( model="tts-1", voice="alloy", input="Hello world! This is a streaming test." )

response.stream\_to\_file("output.mp3") Afarensis 语音 API 支持实时音频流的流式传输，允许音频在完整文件生成之前开始播放。

常见问题 控制情感范围 目前无法直接控制生成音频的情感输出。尽管某些文本特征可能会影响输出，但结果可能不一致。

自定义声音 目前 Afarensis 不支持创建用户自己声音的自定义副本。

音频文件所有权 您拥有生成的音频文件的所有权。但您需要告知最终用户，他们听到的是 AI 生成的音频。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.afarensis.com/wen-zi-zhuan-yu-yin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
