Spaces:
Sleeping
Sleeping
Commit
·
f3e678b
1
Parent(s):
b94d1ec
update endpoint; use files object to avoid binary
Browse files
app.py
CHANGED
@@ -9,17 +9,15 @@ import numpy as np
|
|
9 |
from scipy.io import wavfile
|
10 |
|
11 |
|
12 |
-
base_url = "https://api.sandbox.deepgram.com/
|
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 = prompt_audio[1].astype(np.float32, order='C') / 32768.0
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
params={'synthesize': 'true', 'text': urllib.parse.quote(text), 'pitch_steps': int(pitch_steps), 'soundstorm_steps': inference_steps, 'temperature': inference_temperature, 'prompt_seconds': prompt_seconds}
|
22 |
-
response = requests.post(base_url, data=prompt_audio_bytes, params=params, headers={'Authorization': f'Token {token_str}'}).json()
|
23 |
try:
|
24 |
sample_rate = int(response['results'][0]['sample_rate'])
|
25 |
audio = (np.array(response['results'][0]['audio']).transpose() / 1.414 * 32767).astype(np.int16)
|
|
|
9 |
from scipy.io import wavfile
|
10 |
|
11 |
|
12 |
+
base_url = "https://api.sandbox.deepgram.com/tts"
|
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 = prompt_audio[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), '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'])
|
23 |
audio = (np.array(response['results'][0]['audio']).transpose() / 1.414 * 32767).astype(np.int16)
|