From 275af1ed9e4115cdd632dcf1aed91b8ab05941f4 Mon Sep 17 00:00:00 2001 From: lipku Date: Sat, 7 Sep 2024 13:44:59 +0800 Subject: [PATCH] fix edgetts exception --- app.py | 2 +- basereal.py | 8 ++++++-- ttsreal.py | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 163713e..6591f5c 100644 --- a/app.py +++ b/app.py @@ -169,7 +169,7 @@ async def record(request): sessionid = params.get('sessionid',0) if params['type']=='start_record': # nerfreals[sessionid].put_msg_txt(params['text']) - nerfreals[sessionid].start_recording() + nerfreals[sessionid].start_recording("data/record_lasted.mp4") elif params['type']=='end_record': nerfreals[sessionid].stop_recording() return web.Response( diff --git a/basereal.py b/basereal.py index a7b3fae..60fb952 100644 --- a/basereal.py +++ b/basereal.py @@ -72,14 +72,14 @@ class BaseReal: for key in self.custom_index: self.custom_index[key]=0 - def start_recording(self): + def start_recording(self,path): """开始录制视频""" if self.recording: return self.recording = True self.recordq_video.queue.clear() self.recordq_audio.queue.clear() - self.container = av.open("data/record_lasted.mp4", mode="w") + self.container = av.open(path, mode="w") process_thread = Thread(target=self.record_frame, args=()) process_thread.start() @@ -115,6 +115,10 @@ class BaseReal: except Exception as e: print(e) #break + for packet in videostream.encode(None): + self.container.mux(packet) + for packet in audiostream.encode(None): + self.container.mux(packet) self.container.close() self.recordq_video.queue.clear() self.recordq_audio.queue.clear() diff --git a/ttsreal.py b/ttsreal.py index e5c2c7f..f29e2ba 100644 --- a/ttsreal.py +++ b/ttsreal.py @@ -65,7 +65,10 @@ class EdgeTTS(BaseTTS): t = time.time() asyncio.new_event_loop().run_until_complete(self.__main(voicename,text)) print(f'-------edge tts time:{time.time()-t:.4f}s') - + if self.input_stream.getbuffer().nbytes<=0: #edgetts err + print('edgetts err!!!!!') + return + self.input_stream.seek(0) stream = self.__create_bytes_stream(self.input_stream) streamlen = stream.shape[0]