modify human

This commit is contained in:
brige 2024-09-18 23:48:18 +08:00
parent aa32bd2a82
commit cb9ea0ac17
2 changed files with 9 additions and 10 deletions

View File

@ -81,7 +81,7 @@ def inference(render_event, batch_size, face_images_path, audio_feat_queue, audi
logging.info('start inference')
print(f'start inference: {render_event.is_set()}')
while render_event.is_set():
print('start inference')
mel_batch = []
try:
mel_batch = audio_feat_queue.get(block=True, timeout=1)
except queue.Empty:
@ -139,6 +139,7 @@ def inference(render_event, batch_size, face_images_path, audio_feat_queue, audi
class Human:
def __init__(self):
self._text = None
self._tts = None
self._fps = 50 # 20 ms per frame
self._batch_size = 16
@ -201,18 +202,18 @@ class Human:
self._chunk_2_mal.push_chunk(chunk)
def push_feat_queue(self, mel_chunks):
print("21")
print("push_feat_queue")
self._feat_queue.put(mel_chunks)
print("22")
def push_audio_frames(self, chunk, type_):
print("push_audio_frames")
self._output_queue.put((chunk, type_))
def render(self):
try:
img, aud = self._res_frame_queue.get(block=True, timeout=.3)
except queue.Empty:
print('queue.Empty:')
# print('render queue.Empty:')
return None
return img

View File

@ -23,14 +23,16 @@ class Chunk2Mal:
try:
chunk, type_ = self.pull_chunk()
self._chunks.append(chunk)
self._human.push_audio_frames((chunk, type_))
print("1")
self._human.push_audio_frames(chunk, type_)
except queue.Empty:
# print('Chunk2Mal queue.Empty')
continue
if len(self._chunks) <= self._human.get_stride_left_size() + self._human.get_stride_right_size():
# print('Chunk2Mal queue.Empty')
continue
logging.info('np.concatenate')
inputs = np.concatenate(self._chunks) # [N * chunk]
mel = audio.melspectrogram(inputs)
left = max(0, self._human.get_stride_left_size() * 80 / 50)
@ -41,7 +43,6 @@ class Chunk2Mal:
mel_chunks = []
while i < (len(self._chunks) - self._human.get_stride_left_size()
- self._human.get_stride_right_size()) / 2:
print("14")
start_idx = int(left + i * mel_idx_multiplier)
# print(start_idx)
if start_idx + mel_step_size > len(mel[0]):
@ -49,13 +50,10 @@ class Chunk2Mal:
else:
mel_chunks.append(mel[:, start_idx: start_idx + mel_step_size])
i += 1
print("13")
self._human.push_feat_queue(mel_chunks)
print("15")
# discard the old part to save memory
self._chunks = self._chunks[-(self._human.get_stride_left_size() + self._human.get_stride_right_size()):]
print("12")
logging.info('chunk2mal exit')