mirror of
https://github.com/smittix/intercept.git
synced 2026-04-24 06:40:00 -07:00
Fix Listening Post audio issues
- Add auto-reconnect on audio player errors/stalls - Fix tuneToFrequency to properly wait between stop/start - Improve ffmpeg encoding: 96k bitrate, 44.1kHz output, low latency flags - Increase stream chunk size for smoother playback Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -375,13 +375,19 @@ def _start_audio_stream(frequency: float, modulation: str):
|
||||
|
||||
encoder_cmd = [
|
||||
ffmpeg_path,
|
||||
'-hide_banner',
|
||||
'-loglevel', 'error',
|
||||
'-f', 's16le',
|
||||
'-ar', str(resample_rate),
|
||||
'-ac', '1',
|
||||
'-i', 'pipe:0',
|
||||
'-acodec', 'libmp3lame',
|
||||
'-f', 'mp3',
|
||||
'-b:a', '64k',
|
||||
'-b:a', '96k',
|
||||
'-ar', '44100', # Resample to standard rate for browser compatibility
|
||||
'-flush_packets', '1',
|
||||
'-fflags', '+nobuffer',
|
||||
'-flags', '+low_delay',
|
||||
'pipe:1'
|
||||
]
|
||||
|
||||
@@ -754,12 +760,14 @@ def stream_audio() -> Response:
|
||||
return Response(b'', mimetype='audio/mpeg', status=204)
|
||||
|
||||
def generate():
|
||||
chunk_size = 4096
|
||||
chunk_size = 8192 # Larger chunks for smoother streaming
|
||||
try:
|
||||
while audio_running and audio_process and audio_process.poll() is None:
|
||||
chunk = audio_process.stdout.read(chunk_size)
|
||||
if not chunk:
|
||||
break
|
||||
# Small wait before checking again to avoid busy loop
|
||||
time.sleep(0.01)
|
||||
continue
|
||||
yield chunk
|
||||
except Exception as e:
|
||||
logger.error(f"Audio stream error: {e}")
|
||||
|
||||
Reference in New Issue
Block a user