[异步播报打断]:完成播放中麦克风监听和音色隔离,包含后台监听、助手回放抑制和用户音色打断测试
This commit is contained in:
@@ -113,13 +113,18 @@ class MemoryAudioTransport:
|
||||
*,
|
||||
chunk_ms: int,
|
||||
after_chunk: Callable[[AudioSegment, int], bool] | None = None,
|
||||
should_stop: Callable[[], bool] | None = None,
|
||||
) -> PlaybackResult:
|
||||
elapsed_ms = 0
|
||||
for chunk in _raw_pcm_chunks(segment, chunk_ms=chunk_ms):
|
||||
if should_stop is not None and should_stop():
|
||||
return PlaybackResult(True, elapsed_ms)
|
||||
playback = self.play_pcm(chunk)
|
||||
if playback.error:
|
||||
return playback
|
||||
elapsed_ms += chunk.duration_ms
|
||||
if should_stop is not None and should_stop():
|
||||
return PlaybackResult(True, elapsed_ms)
|
||||
if after_chunk is not None and after_chunk(chunk, elapsed_ms):
|
||||
return PlaybackResult(True, elapsed_ms)
|
||||
return PlaybackResult(True, elapsed_ms)
|
||||
@@ -312,6 +317,7 @@ class SoundDeviceAudioTransport:
|
||||
*,
|
||||
chunk_ms: int,
|
||||
after_chunk: Callable[[AudioSegment, int], bool] | None = None,
|
||||
should_stop: Callable[[], bool] | None = None,
|
||||
) -> PlaybackResult:
|
||||
if self._sd is None or segment.metadata.get("format") in {"aiff", "wav", "mp3", "m4a", "aac"}:
|
||||
playback = self.play_pcm(segment)
|
||||
@@ -341,8 +347,12 @@ class SoundDeviceAudioTransport:
|
||||
device=_coerce_device_id(self._output_device),
|
||||
) as stream:
|
||||
for chunk in _raw_pcm_chunks(segment, chunk_ms=chunk_ms):
|
||||
if should_stop is not None and should_stop():
|
||||
return PlaybackResult(True, elapsed_ms)
|
||||
stream.write(chunk.pcm)
|
||||
elapsed_ms += chunk.duration_ms
|
||||
if should_stop is not None and should_stop():
|
||||
return PlaybackResult(True, elapsed_ms)
|
||||
if after_chunk is not None and after_chunk(chunk, elapsed_ms):
|
||||
return PlaybackResult(True, elapsed_ms)
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user