2024-10-22 11:57:30 +00:00
|
|
|
#encoding = utf8
|
|
|
|
import logging
|
|
|
|
import time
|
|
|
|
from queue import Empty
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
from audio_render import AudioRender
|
2024-10-25 00:23:55 +00:00
|
|
|
from human.message_type import MessageType
|
2024-10-23 09:44:33 +00:00
|
|
|
from .base_render import BaseRender
|
2024-10-22 11:57:30 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class VoiceRender(BaseRender):
|
2024-10-25 00:23:55 +00:00
|
|
|
def __init__(self, play_clock, context):
|
2024-10-22 11:57:30 +00:00
|
|
|
self._audio_render = AudioRender()
|
2024-11-05 11:40:03 +00:00
|
|
|
super().__init__(play_clock, context, 'Voice')
|
2024-10-25 00:23:55 +00:00
|
|
|
|
2024-11-04 05:40:05 +00:00
|
|
|
def render(self, frame, ps):
|
|
|
|
self._play_clock.update_display_time()
|
|
|
|
self._play_clock.current_time = ps
|
|
|
|
|
|
|
|
for audio_frame in frame:
|
|
|
|
frame, type_ = audio_frame
|
2024-11-13 04:58:56 +00:00
|
|
|
chunk, txt = frame
|
|
|
|
chunk = (chunk * 32767).astype(np.int16)
|
2024-11-04 05:40:05 +00:00
|
|
|
|
|
|
|
if self._audio_render is not None:
|
|
|
|
try:
|
2024-11-13 04:58:56 +00:00
|
|
|
chunk_len = int(chunk.shape[0] * 2)
|
2024-11-04 05:40:05 +00:00
|
|
|
# print('audio frame:', frame.shape, chunk_len)
|
2024-11-13 04:58:56 +00:00
|
|
|
self._audio_render.write(chunk.tobytes(), chunk_len)
|
2024-11-04 05:40:05 +00:00
|
|
|
except Exception as e:
|
|
|
|
logging.error(f'Error writing audio frame: {e}')
|