Spaces:
Sleeping
Sleeping
Hugo Rodrigues
commited on
Commit
·
b2b9472
1
Parent(s):
6db451f
remove dependency torchaudio
Browse files
main.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
|
| 2 |
import time
|
| 3 |
from scipy.io.wavfile import write
|
| 4 |
-
import torchaudio
|
| 5 |
import numpy as np
|
| 6 |
|
| 7 |
|
|
@@ -88,21 +87,19 @@ async def audio(inputs, src_lang="eng", tgt_lang="por", speaker_id=5):
|
|
| 88 |
audio_array_from_text = model.generate(
|
| 89 |
**text_inputs, tgt_lang=tgt_lang, speaker_id=int(speaker_id))[0].cpu().numpy().squeeze()
|
| 90 |
|
| 91 |
-
print("Time took to process the request and return response is {} sec".format(
|
| 92 |
-
time.time() - start_time))
|
| 93 |
-
|
| 94 |
-
print(f"sampling_rate {model.config.sampling_rate}")
|
| 95 |
-
|
| 96 |
write(f"/tmp/output{start_time}.wav", model.config.sampling_rate,
|
| 97 |
audio_array_from_text)
|
| 98 |
|
|
|
|
|
|
|
|
|
|
| 99 |
return FileResponse(f"/tmp/output{start_time}.wav", media_type="audio/mpeg")
|
| 100 |
|
| 101 |
|
| 102 |
@app.post("/transcribe-audio")
|
| 103 |
async def transcribe_audio(soundFile: UploadFile, tgt_lang='eng'):
|
| 104 |
start_time = time.time()
|
| 105 |
-
|
| 106 |
inputFile = soundFile.file.read()
|
| 107 |
|
| 108 |
audio_data = np.frombuffer(inputFile, dtype=np.int16)
|
|
@@ -116,4 +113,7 @@ async def transcribe_audio(soundFile: UploadFile, tgt_lang='eng'):
|
|
| 116 |
write(f"/tmp/output{start_time}.wav", model.config.sampling_rate,
|
| 117 |
audio_array_from_audio)
|
| 118 |
|
|
|
|
|
|
|
|
|
|
| 119 |
return FileResponse(f"/tmp/output{start_time}.wav", media_type="audio/wav")
|
|
|
|
| 1 |
|
| 2 |
import time
|
| 3 |
from scipy.io.wavfile import write
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
|
|
|
|
| 87 |
audio_array_from_text = model.generate(
|
| 88 |
**text_inputs, tgt_lang=tgt_lang, speaker_id=int(speaker_id))[0].cpu().numpy().squeeze()
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
write(f"/tmp/output{start_time}.wav", model.config.sampling_rate,
|
| 91 |
audio_array_from_text)
|
| 92 |
|
| 93 |
+
print("Time took to process the request and return response is {} sec".format(
|
| 94 |
+
time.time() - start_time))
|
| 95 |
+
|
| 96 |
return FileResponse(f"/tmp/output{start_time}.wav", media_type="audio/mpeg")
|
| 97 |
|
| 98 |
|
| 99 |
@app.post("/transcribe-audio")
|
| 100 |
async def transcribe_audio(soundFile: UploadFile, tgt_lang='eng'):
|
| 101 |
start_time = time.time()
|
| 102 |
+
|
| 103 |
inputFile = soundFile.file.read()
|
| 104 |
|
| 105 |
audio_data = np.frombuffer(inputFile, dtype=np.int16)
|
|
|
|
| 113 |
write(f"/tmp/output{start_time}.wav", model.config.sampling_rate,
|
| 114 |
audio_array_from_audio)
|
| 115 |
|
| 116 |
+
print("Time took to process the request and return response is {} sec".format(
|
| 117 |
+
time.time() - start_time))
|
| 118 |
+
|
| 119 |
return FileResponse(f"/tmp/output{start_time}.wav", media_type="audio/wav")
|