Skip to content

Commit 8cb5f94

Browse files
committed
update test_tts
1 parent 15d380e commit 8cb5f94

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

tests/test_openai_tts(弃用).py

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/test_openai_tts_stream.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
import base64
12
from pathlib import Path
23
from openai import OpenAI
34

45
speech_file_path = Path(__file__).parent / "speech.mp3"
5-
client = OpenAI(api_key="EMPTY", base_url="http://localhost:8082/v1")
66

7+
8+
with open("../assets/audio_data/roles/余承东/reference_audio.wav", "rb") as f:
9+
audio_bytes = f.read()
10+
audio_base64 = base64.b64encode(audio_bytes).decode("utf-8")
11+
clone_voice = False # 是否使用声音克隆
12+
# 雷军声音
13+
url = "https://s1.aigei.com/src/aud/mp3/59/59b47e28dbc14589974a428180ef338d.mp3?download/%E9%9B%B7%E5%86%9B%E8%AF%AD%E9%9F%B3%E5%8C%85_%E7%88%B1%E7%BB%99%E7%BD%91_aigei_com.mp3&e=1745911680&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:RvcXPTseOqkvy2f_ppELez7d8jY="
14+
if clone_voice:
15+
voice = audio_base64
16+
# voice = url
17+
else:
18+
voice = "新闻联播女声"
19+
20+
client = OpenAI(api_key="EMPTY", base_url="http://localhost:8082/v1")
721
with client.audio.speech.with_streaming_response.create(
822
model="tts",
9-
voice="新闻联播女声", # 暂时仅支持 新闻联播女声
23+
voice=voice, # 内置 新闻联播女声, 支持声音克隆,voice 可以是base64 或者 一个 url
1024
input="本期节目主要内容: 一.习近平在参加北京市区人大代表换届选举投票时强调 不断发展全过程人民民主 加强选举全过程监督",
1125
) as response:
1226
with open(speech_file_path, mode="wb") as f:

0 commit comments

Comments
 (0)