save code
This commit is contained in:
+6
-4
@@ -90,12 +90,14 @@ class ChatPipeline:
|
||||
for i, seg in enumerate(segments):
|
||||
if should_interrupt and should_interrupt():
|
||||
break
|
||||
if on_text_segment is not None:
|
||||
await on_text_segment(seg, i, len(segments))
|
||||
seg_audio, seg_sr = await self.tts.synthesize(seg)
|
||||
if should_interrupt and should_interrupt():
|
||||
break
|
||||
sr = seg_sr
|
||||
if i == 0:
|
||||
first_chunk_ms = int((time.perf_counter() - t0) * 1000)
|
||||
if on_text_segment is not None:
|
||||
await on_text_segment(seg, i, len(segments))
|
||||
if on_audio_chunk is not None:
|
||||
await on_audio_chunk(seg_audio, seg_sr, seg, i, len(segments))
|
||||
audio_chunks.append(seg_audio)
|
||||
@@ -122,13 +124,13 @@ class ChatPipeline:
|
||||
if on_reply_text is not None:
|
||||
await on_reply_text(reply_text)
|
||||
llm_latency_ms = int((time.perf_counter() - llm_t0) * 1000)
|
||||
await self.arbitrator.on_avatar_start()
|
||||
audio, sr, tts_first_chunk_ms, tts_latency_ms = await self._synthesize_sentence_first(
|
||||
reply_text,
|
||||
on_audio_chunk=on_audio_chunk,
|
||||
on_text_segment=on_reply_segment,
|
||||
should_interrupt=lambda: self.arbitrator.cancel_avatar_event.is_set(),
|
||||
)
|
||||
await self.arbitrator.on_avatar_start()
|
||||
playback_s = max(0.2, min(5.0, float(audio.shape[0]) / float(sr)))
|
||||
# Do not block request completion on playback duration.
|
||||
asyncio.create_task(self._finish_avatar_after_playback(playback_s))
|
||||
@@ -157,13 +159,13 @@ class ChatPipeline:
|
||||
if on_reply_text is not None:
|
||||
await on_reply_text(reply_text)
|
||||
llm_latency_ms = int((time.perf_counter() - llm_t0) * 1000)
|
||||
await self.arbitrator.on_avatar_start()
|
||||
audio, sr, tts_first_chunk_ms, tts_latency_ms = await self._synthesize_sentence_first(
|
||||
reply_text,
|
||||
on_audio_chunk=on_audio_chunk,
|
||||
on_text_segment=on_reply_segment,
|
||||
should_interrupt=lambda: self.arbitrator.cancel_avatar_event.is_set(),
|
||||
)
|
||||
await self.arbitrator.on_avatar_start()
|
||||
playback_s = max(0.2, min(5.0, float(audio.shape[0]) / float(sr)))
|
||||
asyncio.create_task(self._finish_avatar_after_playback(playback_s))
|
||||
payload = {
|
||||
|
||||
@@ -32,4 +32,5 @@ class Arbitrator:
|
||||
|
||||
async def on_avatar_done(self) -> None:
|
||||
async with self._lock:
|
||||
self.state = SessionState.IDLE
|
||||
if self.state == SessionState.AVATAR_SPEAKING:
|
||||
self.state = SessionState.IDLE
|
||||
|
||||
Reference in New Issue
Block a user