basic streaming from webinterface is functioning

This commit is contained in:
2025-06-07 13:39:01 +02:00
parent b0e2ae8e83
commit 366d821f8a
5 changed files with 86 additions and 15 deletions

View File

@@ -49,9 +49,12 @@ from bumble.audio import io as audio_io
from auracast import auracast_config
from auracast.utils.read_lc3_file import read_lc3_file
from auracast.network_audio_receiver import NetworkAudioReceiverUncoded
from auracast.utils.network_audio_receiver import NetworkAudioReceiverUncoded
from auracast.utils.webrtc_audio_input import WebRTCAudioInput
# Instantiate WebRTC audio input for streaming (can be used per-BIG or globally)
# modified from bumble
class ModWaveAudioInput(audio_io.ThreadedAudioInput):
"""Audio input that reads PCM samples from a .wav file."""
@@ -357,6 +360,20 @@ class Streamer():
big['encoder'] = encoder
big['precoded'] = False
elif audio_source == 'webrtc':
big['audio_input'] = WebRTCAudioInput()
encoder = lc3.Encoder(
frame_duration_us=global_config.frame_duration_us,
sample_rate_hz=global_config.auracast_sampling_rate_hz,
num_channels=1,
input_sample_rate_hz=48000, # TODO: get samplerate from webrtc
)
lc3_frame_samples = encoder.get_frame_samples()
big['pcm_bit_depth'] = 16
big['lc3_frame_samples'] = lc3_frame_samples
big['encoder'] = encoder
big['precoded'] = False
# precoded lc3 from ram
elif isinstance(big_config[i].audio_source, bytes):
big['precoded'] = True
@@ -470,7 +487,7 @@ class Streamer():
if lc3_frame == b'': # Not all streams may stop at the same time
stream_finished[i] = True
continue
else:
else: # code lc3 on the fly
pcm_frame = await anext(big['audio_input'].frames(big['lc3_frame_samples']), None)
if pcm_frame is None: # Not all streams may stop at the same time
@@ -483,10 +500,10 @@ class Streamer():
await big['iso_queue'].write(lc3_frame)
if all(stream_finished): # Take into account that multiple files have different lengths
logging.info('All streams finished, stopping streamer')
self.is_streaming = False
break
# if all(stream_finished): # Take into account that multiple files have different lengths
# logging.info('All streams finished, stopping streamer')
# self.is_streaming = False
# break
# -----------------------------------------------------------------------------