Skip to content

Commit 6f1450c

Browse files
Merge pull request remsky#310 from fireblade2534/master
Added some better saftey checks to captioned speech
2 parents 36197b9 + 243d98e commit 6f1450c

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

api/src/routers/development.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,13 @@ async def dual_output():
224224
).decode("utf-8")
225225

226226
# Add any chunks that may be in the acumulator into the return word_timestamps
227-
chunk_data.word_timestamps = (
228-
timestamp_acumulator + chunk_data.word_timestamps
229-
)
230-
timestamp_acumulator = []
227+
if chunk_data.word_timestamps is not None:
228+
chunk_data.word_timestamps = (
229+
timestamp_acumulator + chunk_data.word_timestamps
230+
)
231+
timestamp_acumulator = []
232+
else:
233+
chunk_data.word_timestamps = []
231234

232235
yield CaptionedSpeechResponse(
233236
audio=base64_chunk,
@@ -272,7 +275,7 @@ async def single_output():
272275
)
273276

274277
# Add any chunks that may be in the acumulator into the return word_timestamps
275-
if chunk_data.word_timestamps != None:
278+
if chunk_data.word_timestamps is not None:
276279
chunk_data.word_timestamps = (
277280
timestamp_acumulator + chunk_data.word_timestamps
278281
)

dev/Test Phon.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import base64
2+
import json
3+
4+
import pydub
5+
import requests
6+
7+
def generate_audio_from_phonemes(phonemes: str, voice: str = "af_bella"):
8+
"""Generate audio from phonemes"""
9+
response = requests.post(
10+
"http://localhost:8880/dev/generate_from_phonemes",
11+
json={"phonemes": phonemes, "voice": voice},
12+
headers={"Accept": "audio/wav"}
13+
)
14+
if response.status_code != 200:
15+
print(f"Error: {response.text}")
16+
return None
17+
return response.content
18+
19+
20+
21+
22+
with open(f"outputnostreammoney.wav", "wb") as f:
23+
f.write(generate_audio_from_phonemes(r"mɪsəki ɪz ɐn ɪkspˌɛɹəmˈɛntᵊl ʤˈitəpˈi ˈɛnʤən dəzˈInd tə pˈWəɹ fjˈuʧəɹ vˈɜɹʒənz ʌv kəkˈɔɹO mˈɑdᵊlz."))

0 commit comments

Comments
 (0)