[播放平滑修复]:完成可打断播报平滑播放,包含单输出流分块播放和TTS采样率保真
This commit is contained in:
@@ -114,6 +114,24 @@ class TransportTests(unittest.TestCase):
|
||||
|
||||
self.assertTrue(result.played)
|
||||
self.assertEqual(fake.output_writes, [b"\x00\x00\x01\x00"])
|
||||
self.assertEqual(fake.output_stream_open_count, 1)
|
||||
|
||||
def test_sounddevice_chunk_playback_keeps_one_output_stream_open(self) -> None:
|
||||
fake = FakeSoundDevice()
|
||||
transport = SoundDeviceAudioTransport(sounddevice_module=fake)
|
||||
segment = AudioSegment(b"\x00\x00" * 1600, 16000, 1, 0, 100)
|
||||
callbacks: list[int] = []
|
||||
|
||||
result = transport.play_pcm_chunks(
|
||||
segment,
|
||||
chunk_ms=20,
|
||||
after_chunk=lambda _chunk, elapsed_ms: callbacks.append(elapsed_ms) is not None and False,
|
||||
)
|
||||
|
||||
self.assertTrue(result.played)
|
||||
self.assertEqual(fake.output_stream_open_count, 1)
|
||||
self.assertGreater(len(fake.output_writes), 1)
|
||||
self.assertEqual(callbacks[-1], result.duration_ms)
|
||||
|
||||
def test_sounddevice_device_report_uses_query_devices(self) -> None:
|
||||
fake = FakeSoundDevice()
|
||||
@@ -162,6 +180,7 @@ class FakeSoundDevice:
|
||||
def __init__(self, callback_payloads: list[bytes] | None = None) -> None:
|
||||
self.callback_payloads = callback_payloads
|
||||
self.output_writes: list[bytes] = []
|
||||
self.output_stream_open_count = 0
|
||||
|
||||
def RawInputStream(self, **kwargs):
|
||||
if self.callback_payloads is not None:
|
||||
@@ -169,6 +188,7 @@ class FakeSoundDevice:
|
||||
return FakeInputStream(**kwargs)
|
||||
|
||||
def RawOutputStream(self, **kwargs):
|
||||
self.output_stream_open_count += 1
|
||||
return FakeOutputStream(self, **kwargs)
|
||||
|
||||
def query_devices(self):
|
||||
|
||||
Reference in New Issue
Block a user