Compare commits
3 Commits
dba250b798
...
e6d9f5ad9d
Author | SHA1 | Date | |
---|---|---|---|
e6d9f5ad9d | |||
11d6e8ca84 | |||
13c78c882f |
20
app.py
20
app.py
@ -45,17 +45,7 @@ def start_recording():
|
|||||||
is_recording = True
|
is_recording = True
|
||||||
start_time = time.time() # Record the start time
|
start_time = time.time() # Record the start time
|
||||||
print("Recording started...")
|
print("Recording started...")
|
||||||
recorded_audio = [] # Start with an empty list to store audio chunks
|
recorded_audio = sd.rec(int(SAMPLE_RATE * 600), samplerate=SAMPLE_RATE, channels=1, dtype=np.float32)
|
||||||
|
|
||||||
# Start recording continuously
|
|
||||||
def callback(indata, frames, time, status):
|
|
||||||
if is_recording: # Append audio data only while recording
|
|
||||||
recorded_audio.append(indata.copy())
|
|
||||||
|
|
||||||
stream = sd.InputStream(
|
|
||||||
samplerate=SAMPLE_RATE, channels=1, dtype=np.float32, callback=callback
|
|
||||||
)
|
|
||||||
stream.start() # Start the stream
|
|
||||||
return "Recording... Click 'Stop Recording' to finish."
|
return "Recording... Click 'Stop Recording' to finish."
|
||||||
|
|
||||||
|
|
||||||
@ -67,12 +57,8 @@ def stop_recording():
|
|||||||
is_recording = False
|
is_recording = False
|
||||||
elapsed_time = time.time() - start_time # Calculate elapsed time
|
elapsed_time = time.time() - start_time # Calculate elapsed time
|
||||||
print(f"Recording stopped. Duration: {elapsed_time:.2f} seconds.")
|
print(f"Recording stopped. Duration: {elapsed_time:.2f} seconds.")
|
||||||
|
save_audio_to_wav(recorded_audio[:int(SAMPLE_RATE * elapsed_time)], FILENAME) # Truncate to actual duration
|
||||||
# Combine all recorded chunks into a single array
|
return "Recording stopped. Click 'Transcribe' to see the result."
|
||||||
audio_data = np.concatenate(recorded_audio, axis=0)
|
|
||||||
save_audio_to_wav(audio_data[: int(SAMPLE_RATE * elapsed_time)], FILENAME)
|
|
||||||
return f"Recording stopped. Duration: {elapsed_time:.2f} seconds. Click 'Transcribe' to see the result."
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def save_audio_to_wav(audio, filename):
|
def save_audio_to_wav(audio, filename):
|
||||||
|
Loading…
Reference in New Issue
Block a user