cuio commited on
Commit
190f5a2
·
verified ·
1 Parent(s): b4a81bb

Update backend/open_webui/apps/audio/main.py

Browse files
backend/open_webui/apps/audio/main.py CHANGED
@@ -7,6 +7,7 @@ from functools import lru_cache
7
  from pathlib import Path
8
  from pydub import AudioSegment
9
  from pydub.silence import split_on_silence
 
10
 
11
  import requests
12
  from open_webui.config import (
@@ -252,25 +253,36 @@ async def speech(request: Request, user=Depends(get_verified_user)):
252
  body = body.decode("utf-8")
253
  body = json.loads(body)
254
  body["model"] = app.state.config.TTS_MODEL
 
 
255
  body = json.dumps(body).encode("utf-8")
256
  except Exception:
257
  pass
258
 
259
  r = None
260
  try:
261
- r = requests.post(
262
- url=f"{app.state.config.TTS_OPENAI_API_BASE_URL}/audio/speech",
263
- data=body,
264
- headers=headers,
265
- stream=True,
 
 
266
  )
267
 
268
- r.raise_for_status()
 
 
 
 
 
 
 
269
 
270
  # Save the streaming content to a file
271
  with open(file_path, "wb") as f:
272
- for chunk in r.iter_content(chunk_size=8192):
273
- f.write(chunk)
274
 
275
  with open(file_body_path, "w") as f:
276
  json.dump(json.loads(body.decode("utf-8")), f)
 
7
  from pathlib import Path
8
  from pydub import AudioSegment
9
  from pydub.silence import split_on_silence
10
+ from gradio_client import Client, file
11
 
12
  import requests
13
  from open_webui.config import (
 
253
  body = body.decode("utf-8")
254
  body = json.loads(body)
255
  body["model"] = app.state.config.TTS_MODEL
256
+ query=body["input"]
257
+ print(query)
258
  body = json.dumps(body).encode("utf-8")
259
  except Exception:
260
  pass
261
 
262
  r = None
263
  try:
264
+ client = Client("https://s5k.cn/api/v1/studio/iic/CosyVoice-300M-WAIC/gradio/")
265
+ r= client.predict(
266
+ _sound_radio="中文女",
267
+ _synthetic_input_textbox={"query":query},
268
+ _seed=0,
269
+ api_name="/generate_audio"
270
+
271
  )
272
 
273
+ #r = requests.post(
274
+ # url=f"{app.state.config.TTS_OPENAI_API_BASE_URL}/audio/speech",
275
+ #data=body,
276
+ # headers=headers,
277
+ # stream=True,
278
+ #)
279
+
280
+ # r.raise_for_status()
281
 
282
  # Save the streaming content to a file
283
  with open(file_path, "wb") as f:
284
+ # for chunk in r.iter_content(chunk_size=8192):
285
+ f.write(r.content)
286
 
287
  with open(file_body_path, "w") as f:
288
  json.dump(json.loads(body.decode("utf-8")), f)