fix edge tts audio

This commit is contained in:
lipku 2024-03-09 10:00:31 +08:00
parent 3c84f9838b
commit 39dd3dcc4c
1 changed files with 27 additions and 28 deletions

View File

@ -385,14 +385,12 @@ class ASR:
def push_audio(self,buffer): def push_audio(self,buffer):
print(f'[INFO] push_audio {len(buffer)}') print(f'[INFO] push_audio {len(buffer)}')
if len(buffer)>0:
if self.opt.tts == "xtts": if self.opt.tts == "xtts":
if len(buffer)>0:
stream = np.frombuffer(buffer, dtype=np.int16).astype(np.float32) / 32767 stream = np.frombuffer(buffer, dtype=np.int16).astype(np.float32) / 32767
#stream = buffer.astype(np.float32)
stream = resampy.resample(x=stream, sr_orig=24000, sr_new=self.sample_rate) stream = resampy.resample(x=stream, sr_orig=24000, sr_new=self.sample_rate)
else: #byte_stream=BytesIO(buffer)
byte_stream=BytesIO(buffer) #stream = self.create_bytes_stream(byte_stream)
stream = self.create_bytes_stream(byte_stream)
streamlen = stream.shape[0] streamlen = stream.shape[0]
idx=0 idx=0
while streamlen >= self.chunk: while streamlen >= self.chunk:
@ -401,20 +399,21 @@ class ASR:
idx += self.chunk idx += self.chunk
# if streamlen>0: #skip last frame(not 20ms) # if streamlen>0: #skip last frame(not 20ms)
# self.queue.put(stream[idx:]) # self.queue.put(stream[idx:])
# self.input_stream.write(buffer) else: #edge tts
# if len(buffer)<=0: self.input_stream.write(buffer)
# self.input_stream.seek(0) if len(buffer)<=0:
# stream = self.create_bytes_stream(self.input_stream) self.input_stream.seek(0)
# streamlen = stream.shape[0] stream = self.create_bytes_stream(self.input_stream)
# idx=0 streamlen = stream.shape[0]
# while streamlen >= self.chunk: idx=0
# self.queue.put(stream[idx:idx+self.chunk]) while streamlen >= self.chunk:
# streamlen -= self.chunk self.queue.put(stream[idx:idx+self.chunk])
# idx += self.chunk streamlen -= self.chunk
# #if streamlen>0: #skip last frame(not 20ms) idx += self.chunk
# # self.queue.put(stream[idx:]) #if streamlen>0: #skip last frame(not 20ms)
# self.input_stream.seek(0) # self.queue.put(stream[idx:])
# self.input_stream.truncate() self.input_stream.seek(0)
self.input_stream.truncate()
def get_audio_out(self): def get_audio_out(self):
return self.output_queue.get() return self.output_queue.get()