Spaces:
Sleeping
Sleeping
AshDavid12
commited on
Commit
·
49c6a26
1
Parent(s):
3705f28
create temp dir for audio files
Browse files
infer.py
CHANGED
@@ -193,6 +193,8 @@ async def websocket_transcribe(websocket: WebSocket):
|
|
193 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio_file:
|
194 |
logging.info(f"Temporary audio file created at {temp_audio_file.name}")
|
195 |
#temp_audio_filename = os.path.basename(temp_audio_file.name)
|
|
|
|
|
196 |
|
197 |
while True:
|
198 |
try:
|
@@ -204,7 +206,7 @@ async def websocket_transcribe(websocket: WebSocket):
|
|
204 |
|
205 |
chunk_counter = 0
|
206 |
# Create a new file for the chunk
|
207 |
-
chunk_filename = f"audio_chunk_{chunk_counter}.wav"
|
208 |
chunk_counter += 1
|
209 |
with open(chunk_filename, 'wb') as audio_file:
|
210 |
audio_file.write(audio_chunk)
|
@@ -235,7 +237,7 @@ async def websocket_transcribe(websocket: WebSocket):
|
|
235 |
response = {
|
236 |
"new_segments": partial_result['new_segments'],
|
237 |
"processed_segments": processed_segments,
|
238 |
-
"download_url": f"https://gigaverse-ivrit-ai-streaming.hf.space/download_audio/{chunk_filename}"
|
239 |
}
|
240 |
logging.info(f"Sending {len(partial_result['new_segments'])} new segments to the client.")
|
241 |
await websocket.send_json(response)
|
|
|
193 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio_file:
|
194 |
logging.info(f"Temporary audio file created at {temp_audio_file.name}")
|
195 |
#temp_audio_filename = os.path.basename(temp_audio_file.name)
|
196 |
+
output_directory = "/tmp"
|
197 |
+
os.makedirs(output_directory, exist_ok=True)
|
198 |
|
199 |
while True:
|
200 |
try:
|
|
|
206 |
|
207 |
chunk_counter = 0
|
208 |
# Create a new file for the chunk
|
209 |
+
chunk_filename = os.path.join(output_directory, f"audio_chunk_{chunk_counter}.wav")
|
210 |
chunk_counter += 1
|
211 |
with open(chunk_filename, 'wb') as audio_file:
|
212 |
audio_file.write(audio_chunk)
|
|
|
237 |
response = {
|
238 |
"new_segments": partial_result['new_segments'],
|
239 |
"processed_segments": processed_segments,
|
240 |
+
"download_url": f"https://gigaverse-ivrit-ai-streaming.hf.space/download_audio/{os.path.basename(chunk_filename)})"
|
241 |
}
|
242 |
logging.info(f"Sending {len(partial_result['new_segments'])} new segments to the client.")
|
243 |
await websocket.send_json(response)
|