Mira1sen commited on
Commit
4eb6878
1 Parent(s): 3695ec3

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. tts_gradio.py +9 -7
tts_gradio.py CHANGED
@@ -10,7 +10,7 @@ import os
10
  import re
11
  import tempfile
12
  # import librosa
13
- # import numpy as np
14
  # import torch
15
  # from torch import no_grad, LongTensor
16
  # import commons
@@ -166,7 +166,8 @@ def openai(text, name):
166
  # exactly as it was in the original request.
167
  #data = '{\n "model": "tts-1",\n "input": "The quick brown fox jumped over the lazy dog.",\n "voice": "alloy"\n }'
168
  #response = requests.post('https://api.openai.com/v1/audio/speech', headers=headers, data=data)
169
- return "Success", response
 
170
 
171
  def elevenlabs(text,name):
172
  url = f"https://api.elevenlabs.io/v1/text-to-speech/{eleven_id_model_name_dict[name]}"
@@ -221,11 +222,11 @@ def microsoft(text, name, style="Neural"):
221
  data=data,
222
  )
223
  # breakpoint()
224
- timestamp = int(time.time()*10000)
225
- path = f'/tmp/output_{timestamp}.wav'
226
- with open(path, 'wb') as f:
227
- f.write(response.content)
228
- return "Success", path
229
 
230
  if __name__ == '__main__':
231
  parser = argparse.ArgumentParser()
@@ -271,6 +272,7 @@ if __name__ == '__main__':
271
  app.queue(max_size=10)
272
  app.launch(share=True)
273
  # _, audio = microsoft(all_example,microsoft_model_list[0])
 
274
  # print(audio)
275
  # with open("test99.mp3", "wb") as f:
276
  # f.write(audio.content)
 
10
  import re
11
  import tempfile
12
  # import librosa
13
+ import numpy as np
14
  # import torch
15
  # from torch import no_grad, LongTensor
16
  # import commons
 
166
  # exactly as it was in the original request.
167
  #data = '{\n "model": "tts-1",\n "input": "The quick brown fox jumped over the lazy dog.",\n "voice": "alloy"\n }'
168
  #response = requests.post('https://api.openai.com/v1/audio/speech', headers=headers, data=data)
169
+ out_arr = np.frombuffer(response.content, dtype=np.uint8)
170
+ return "Success", (24000,out_arr)
171
 
172
  def elevenlabs(text,name):
173
  url = f"https://api.elevenlabs.io/v1/text-to-speech/{eleven_id_model_name_dict[name]}"
 
222
  data=data,
223
  )
224
  # breakpoint()
225
+ # timestamp = int(time.time()*10000)
226
+ # path = f'/tmp/output_{timestamp}.wav' # TODO: disk might full.
227
+ # with open(path, 'wb') as f:
228
+ # f.write(response.content)
229
+ return "Success", response
230
 
231
  if __name__ == '__main__':
232
  parser = argparse.ArgumentParser()
 
272
  app.queue(max_size=10)
273
  app.launch(share=True)
274
  # _, audio = microsoft(all_example,microsoft_model_list[0])
275
+ # breakpoint()
276
  # print(audio)
277
  # with open("test99.mp3", "wb") as f:
278
  # f.write(audio.content)