Hello @Raffaele Aldrigo ,
Thanks for the update.
Since you can not accept your own answer I am posting it as a solution please accept
it so that it will help the community to find better solution.
Issue: Live transcription using Azure speech SDK with streamlit_webrtc
not working in Python Streamlit app.
Solution:
Updated code
def transcribe_webrtc(self, webrtc_ctx: WebRtcStreamerContext) -> str:
push_stream = PushAudioInputStream()
audio_config = AudioConfig(stream=push_stream)
transcriber = self.setup_transcriber(audio_config)
transcriber.start_transcribing_async()
logger.info("Started WebRTC transcription")
try:
while webrtc_ctx.state.playing:
audio_frames = webrtc_ctx.audio_receiver.get_frames(timeout=1)
if not audio_frames:
logger.debug("No audio frames received")
continue
frame = pydub.AudioSegment.empty()
for audio_frame in audio_frames:
sound = pydub.AudioSegment(
data=audio_frame.to_ndarray().tobytes(),
sample_width=audio_frame.format.bytes,
frame_rate=audio_frame.sample_rate,
channels=len(audio_frame.layout.channels),
)
frame += sound
if len(frame) > 0:
logger.debug(f"Processing audio frame of length {len(frame.raw_data)} bytes")
frame= frame.set_channels(1).set_frame_rate(16000)
push_stream.write(frame.raw_data)
if self.on_transcribed:
self.on_transcribed("\\\n".join(self.results))
time.sleep(0.1)
Thank you