stevenhillis commited on
Commit
9bcb0d8
1 Parent(s): 0270007

prompt audio as bytestring

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -14,9 +14,13 @@ token_str = os.environ['DG_TOKEN']
14
  def tts_fn(text, prompt_audio, prompt_seconds, inference_steps, inference_temperature, pitch_steps):
15
  texts = [text]
16
  sr = prompt_audio[0]
17
- prompt_audio = np.reshape(prompt_audio[1], (1, 1, -1)).astype(np.float32, order='C') / 32768.0
 
 
 
 
18
  params={'synthesize': 'true', 'pitch_steps': int(pitch_steps), 'soundstorm_steps': inference_steps, 'temperature': inference_temperature, 'prompt_seconds': prompt_seconds}
19
- files=[('texts', ('texts', json.dumps(texts), 'application/json')), ('prompt_audio', ('prompt_audio', json.dumps(prompt_audio.tolist()), 'application/json'))]
20
  response = requests.post(base_url, files=files, params=params, headers={'Authorization': f'Token {token_str}'}).json()
21
  try:
22
  sample_rate = int(response['results'][0]['sample_rate'])
 
14
  def tts_fn(text, prompt_audio, prompt_seconds, inference_steps, inference_temperature, pitch_steps):
15
  texts = [text]
16
  sr = prompt_audio[0]
17
+ prompt_audio = np.reshape(prompt_audio[1], (1, -1)).astype(np.float32, order='C') / 32768.0
18
+ byte_io = io.BytesIO(bytes())
19
+ wavfile.write(byte_io, sr, prompt_audio)
20
+ prompt_audio_bytes = byte_io.read()
21
+ prompt_audio = [base64.b64encode(prompt_audio_bytes).decode('utf-8')] * len(texts)
22
  params={'synthesize': 'true', 'pitch_steps': int(pitch_steps), 'soundstorm_steps': inference_steps, 'temperature': inference_temperature, 'prompt_seconds': prompt_seconds}
23
+ files=[('texts', ('texts', json.dumps(texts), 'application/json')), ('prompt_audio', ('prompt_audio', json.dumps(prompt_audio), 'application/json'))]
24
  response = requests.post(base_url, files=files, params=params, headers={'Authorization': f'Token {token_str}'}).json()
25
  try:
26
  sample_rate = int(response['results'][0]['sample_rate'])