Spaces:
Sleeping
Sleeping
AshDavid12
commited on
Commit
·
7456852
1
Parent(s):
da37a77
added with tempfile dir tmp
Browse files
client.py
CHANGED
@@ -52,17 +52,17 @@ async def receive_transcription(websocket):
|
|
52 |
transcription = await websocket.recv() # Receive transcription from the server
|
53 |
print(f"Transcription: {transcription}")
|
54 |
transcription = json.loads(transcription)
|
55 |
-
download_url = transcription.get('download_url')
|
56 |
-
if download_url:
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
except Exception as e:
|
67 |
print(f"Error receiving transcription: {e}")
|
68 |
break
|
|
|
52 |
transcription = await websocket.recv() # Receive transcription from the server
|
53 |
print(f"Transcription: {transcription}")
|
54 |
transcription = json.loads(transcription)
|
55 |
+
#download_url = transcription.get('download_url')
|
56 |
+
# if download_url:
|
57 |
+
# print(f"Download URL: {download_url}")
|
58 |
+
# # Download the audio file
|
59 |
+
# response = requests.get(download_url)
|
60 |
+
# if response.status_code == 200:
|
61 |
+
# with open("downloaded_audio.wav", "wb") as f:
|
62 |
+
# f.write(response.content)
|
63 |
+
# print("File downloaded successfully")
|
64 |
+
# else:
|
65 |
+
# print(f"Failed to download file. Status code: {response.status_code}")
|
66 |
except Exception as e:
|
67 |
print(f"Error receiving transcription: {e}")
|
68 |
break
|
infer.py
CHANGED
@@ -224,25 +224,27 @@ async def websocket_transcribe(websocket: WebSocket):
|
|
224 |
logging.info("Buffered enough audio time, starting transcription.")
|
225 |
|
226 |
# Create a temporary WAV file in /tmp for transcription
|
227 |
-
|
228 |
-
|
229 |
-
wav_file.setnchannels(channels)
|
230 |
-
wav_file.setsampwidth(sample_width)
|
231 |
-
wav_file.setframerate(sample_rate)
|
232 |
-
wav_file.writeframes(pcm_audio_buffer)
|
233 |
|
234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
# Log to confirm that the file exists and has the expected size
|
237 |
-
if os.path.exists(
|
238 |
-
file_size = os.path.getsize(
|
239 |
logging.info(f"Temporary WAV file size: {file_size} bytes.")
|
240 |
else:
|
241 |
-
logging.error(f"Temporary WAV file {
|
242 |
-
raise Exception(f"Temporary WAV file {
|
243 |
|
244 |
# Call the transcription function with the WAV file path
|
245 |
-
partial_result, last_transcribed_time = transcribe_core_ws(
|
246 |
processed_segments.extend(partial_result['new_segments'])
|
247 |
|
248 |
# Clear the buffer after transcription
|
|
|
224 |
logging.info("Buffered enough audio time, starting transcription.")
|
225 |
|
226 |
# Create a temporary WAV file in /tmp for transcription
|
227 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False, dir="/tmp") as temp_wav_file:
|
228 |
+
logging.info(f"Temporary audio file created at {temp_wav_file.name}")
|
|
|
|
|
|
|
|
|
229 |
|
230 |
+
with wave.open(temp_wav_file.name, 'wb') as wav_file:
|
231 |
+
wav_file.setnchannels(channels)
|
232 |
+
wav_file.setsampwidth(sample_width)
|
233 |
+
wav_file.setframerate(sample_rate)
|
234 |
+
wav_file.writeframes(pcm_audio_buffer)
|
235 |
+
|
236 |
+
logging.info(f"Temporary WAV file created at {temp_wav_file.name} for transcription.")
|
237 |
|
238 |
# Log to confirm that the file exists and has the expected size
|
239 |
+
if os.path.exists(temp_wav_file.name):
|
240 |
+
file_size = os.path.getsize(temp_wav_file.name)
|
241 |
logging.info(f"Temporary WAV file size: {file_size} bytes.")
|
242 |
else:
|
243 |
+
logging.error(f"Temporary WAV file {temp_wav_file.name} does not exist.")
|
244 |
+
raise Exception(f"Temporary WAV file {temp_wav_file.name} not found.")
|
245 |
|
246 |
# Call the transcription function with the WAV file path
|
247 |
+
partial_result, last_transcribed_time = transcribe_core_ws(temp_wav_file.name, last_transcribed_time)
|
248 |
processed_segments.extend(partial_result['new_segments'])
|
249 |
|
250 |
# Clear the buffer after transcription
|