25
25
from .request_params import ChunkLength , ServeReferenceAudio , ServeTTSRequest
26
26
27
27
is_reference_id_first = config .online_model_first
28
- online_api_proxy = config .online_api_proxy
28
+ API_URL = config .online_api_url
29
+ API_PROXY = config .online_api_proxy
30
+ IS_STREAM = config .tts_is_stream
31
+ MAX_NEW_TOKENS = config .tts_max_new_tokens
29
32
30
33
31
34
class FishAudioAPI :
@@ -34,9 +37,9 @@ class FishAudioAPI:
34
37
"""
35
38
36
39
def __init__ (self ):
37
- self .url : str = "https://api.fish.audio/v1/tts"
40
+ self .api_url : str = API_URL
38
41
self .path_audio : Path = Path (config .tts_audio_path )
39
- self .proxy = online_api_proxy
42
+ self .proxy = API_PROXY
40
43
41
44
# 如果在线授权码为空, 且使用在线api, 则抛出异常
42
45
if not config .online_authorization and config .tts_is_online :
@@ -65,7 +68,7 @@ async def _get_reference_id_by_speaker(self, speaker: str) -> str:
65
68
exception:
66
69
APIException: 获取语音角色列表为空
67
70
"""
68
- request_api = "https://api.fish.audio /model"
71
+ request_api = self . api_url + " /model"
69
72
sort_options = ["score" , "task_count" , "created_at" ]
70
73
async with AsyncClient (proxy = self .proxy ) as client :
71
74
for sort_by in sort_options :
@@ -128,6 +131,8 @@ async def generate_servettsrequest(
128
131
opus_bitrate = 24 ,
129
132
normalize = True ,
130
133
chunk_length = chunk_length .value ,
134
+ max_new_tokens = MAX_NEW_TOKENS ,
135
+ streaming = IS_STREAM ,
131
136
references = references ,
132
137
)
133
138
@@ -148,7 +153,7 @@ async def generate_tts(self, request: ServeTTSRequest) -> bytes:
148
153
AsyncClient (proxy = self .proxy ) as client ,
149
154
client .stream (
150
155
"POST" ,
151
- self .url ,
156
+ self .api_url + "/v1/tts" ,
152
157
headers = self .headers ,
153
158
content = ormsgpack .packb (
154
159
request .dict (),
@@ -170,7 +175,7 @@ async def generate_tts(self, request: ServeTTSRequest) -> bytes:
170
175
try :
171
176
async with AsyncClient (proxy = self .proxy ) as client :
172
177
response = await client .post (
173
- self .url ,
178
+ self .api_url + "/v1/tts" ,
174
179
headers = self .headers ,
175
180
json = request .dict (),
176
181
timeout = 60 ,
@@ -191,7 +196,7 @@ async def get_balance(self) -> float:
191
196
"""
192
197
获取账户余额
193
198
"""
194
- balance_url = "https://api.fish.audio /wallet/self/api-credit"
199
+ balance_url = self . api_url + " /wallet/self/api-credit"
195
200
async with AsyncClient (proxy = self .proxy ) as client :
196
201
response = await client .get (balance_url , headers = self .headers )
197
202
try :
@@ -204,7 +209,7 @@ def get_speaker_list(self) -> list[str]:
204
209
获取语音角色列表
205
210
"""
206
211
return_list = ["请查看官网了解更多: https://fish.audio/zh-CN/" ]
207
- if is_reference_id_first :
212
+ if not is_reference_id_first :
208
213
try :
209
214
return_list .extend (get_path_speaker_list (self .path_audio ))
210
215
except FileHandleException :
0 commit comments