| 
					
				 | 
			
			
				@@ -5,6 +5,7 @@ import json 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import random 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import re 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import time 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+from pydub import AudioSegment 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class TTS: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -67,6 +68,10 @@ class TTS: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 with open(f"{pw_mp3_path}", "wb") as file: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     # 将响应内容写入文件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     file.write(response.content) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                # 增加音频音量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                audio = AudioSegment.from_file(pw_mp3_path) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                louder_audio = audio + 10 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                louder_audio.export(pw_mp3_path, format="mp3") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 time.sleep(5) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return pw_mp3_path 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return '' 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -92,6 +97,57 @@ class TTS: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         print(srt_content) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return srt_content 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @classmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    def process_srt(cls, srt): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        lines = srt.strip().split('\n') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        processed_lines = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for line in lines: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if re.match(r'^\d+$', line): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                processed_lines.append(line) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            elif re.match(r'^\d{2}:\d{2}:\d{2}\.\d{1,3}-->\d{2}:\d{2}:\d{2}\.\d{1,3}$', line): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                processed_lines.append(line.replace('-->', ' --> ')) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                line = re.sub(r'[,。!?;、]$', '', line) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                # 添加换行符 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                processed_lines.append(line + '\n') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return '\n'.join(processed_lines) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @classmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    def getSrt(cls, mp3_id): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        url = "http://api-internal.piaoquantv.com/produce-center/srt/get/content" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        payload = json.dumps({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "params": { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                "resourceChannel": "outer", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                "videoPath": mp3_id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        headers = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'Content-Type': 'application/json', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'Accept': '*/*', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'Host': 'api-internal.piaoquantv.com', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'Connection': 'keep-alive' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        response = requests.request("POST", url, headers=headers, data=payload) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        time.sleep(1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data_list = response.json() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        code = data_list["code"] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if code == 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            srt = data_list["data"] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if srt: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                srt = srt.replace("/n", "\n") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                # srt = re.sub(r'(\w+)([,。!?])', r'\n\n', srt) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                new_srt = cls.process_srt(srt) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return new_srt 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return None 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return None 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 if __name__ == '__main__': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     text = "真是太实用了,分享给身边的准妈妈们吧!这些孕期禁忌一定要记住,赶紧转发给更多人,帮助更多的宝妈们。一起为宝宝的健康加油!" 
			 |