Spaces:
Sleeping
Sleeping
Commit
•
ccbb9b9
1
Parent(s):
6a9e916
send encoded bytes not numpy
Browse files
app.py
CHANGED
@@ -10,10 +10,16 @@ base_url = "https://api.sandbox.deepgram.com/nlu"
|
|
10 |
token_str = os.environ['DG_TOKEN']
|
11 |
def tts_fn(text, prompt_audio, prompt_seconds, inference_steps, inference_temperature, pitch_steps):
|
12 |
texts = [text]
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
response = requests.post(
|
15 |
f'{base_url}',
|
16 |
-
files=[('texts', ('texts', json.dumps(texts), 'application/json')), ('prompt_audio', ('prompt_audio', json.dumps(prompt_audio
|
17 |
params={'synthesize': 'true', 'pitch_steps': int(pitch_steps), 'soundstorm_steps': inference_steps, 'temperature': inference_temperature, 'prompt_seconds': prompt_seconds},
|
18 |
headers={
|
19 |
'Authorization': f'Token {token_str}'
|
|
|
10 |
token_str = os.environ['DG_TOKEN']
|
11 |
def tts_fn(text, prompt_audio, prompt_seconds, inference_steps, inference_temperature, pitch_steps):
|
12 |
texts = [text]
|
13 |
+
sr = prompt_audio[0]
|
14 |
+
prompt_audio = np.reshape(prompt_audio[1], (1, -1)).astype(np.float32, order='C') / 32768.0
|
15 |
+
audio_bytes = bytes()
|
16 |
+
byte_io = io.BytesIO(audio_bytes)
|
17 |
+
wavfile.write(byte_io, sr, prompt_audio)
|
18 |
+
prompt_audio = [base64.b64encode(byte_io).decode('utf-8')]
|
19 |
+
|
20 |
response = requests.post(
|
21 |
f'{base_url}',
|
22 |
+
files=[('texts', ('texts', json.dumps(texts), 'application/json')), ('prompt_audio', ('prompt_audio', json.dumps(prompt_audio), 'application/json'))],
|
23 |
params={'synthesize': 'true', 'pitch_steps': int(pitch_steps), 'soundstorm_steps': inference_steps, 'temperature': inference_temperature, 'prompt_seconds': prompt_seconds},
|
24 |
headers={
|
25 |
'Authorization': f'Token {token_str}'
|