fix: try smoothing playback
This commit is contained in:
parent
d37757d764
commit
92ebb47849
1 changed files with 23 additions and 5 deletions
|
|
@ -240,13 +240,31 @@ class SpeechToText:
|
||||||
)
|
)
|
||||||
print(f"Using device default sample rate: {device_info['defaultSampleRate']}")
|
print(f"Using device default sample rate: {device_info['defaultSampleRate']}")
|
||||||
|
|
||||||
# Play the audio
|
# Play the audio with larger buffer for smoother playback
|
||||||
chunk_size = 1024
|
# Using larger chunk size and adding a small delay to allow the buffer to fill
|
||||||
data = wf.readframes(chunk_size)
|
chunk_size = 8192 # Increased from 1024 to reduce stuttering
|
||||||
|
|
||||||
while len(data) > 0:
|
# Pre-buffer data for smoother playback
|
||||||
output_stream.write(data)
|
audio_data = []
|
||||||
|
while True:
|
||||||
data = wf.readframes(chunk_size)
|
data = wf.readframes(chunk_size)
|
||||||
|
if len(data) == 0:
|
||||||
|
break
|
||||||
|
audio_data.append(data)
|
||||||
|
|
||||||
|
# Reset file position for playback
|
||||||
|
wf.rewind()
|
||||||
|
|
||||||
|
# Set a larger buffer size for output
|
||||||
|
buffer_size = chunk_size * 4
|
||||||
|
|
||||||
|
print(f"Playing audio with buffer size {buffer_size} bytes")
|
||||||
|
|
||||||
|
# Play the buffered data with lower CPU load
|
||||||
|
for data in audio_data:
|
||||||
|
output_stream.write(data)
|
||||||
|
# Small sleep to reduce CPU load and allow buffer to process
|
||||||
|
time.sleep(0.005)
|
||||||
|
|
||||||
# Clean up resources
|
# Clean up resources
|
||||||
output_stream.stop_stream()
|
output_stream.stop_stream()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue