zhangyong 11 months ago
parent
commit
26df59fa27
3 changed files with 93 additions and 26 deletions
  1. 19 0
      common/aliyun_oss.py
  2. 68 25
      common/tts_help.py
  3. 6 1
      video_rewriting/video_processor.py

+ 19 - 0
common/aliyun_oss.py

@@ -82,6 +82,25 @@ class Oss():
             }
         raise AssertionError(f'OSS上传失败,请求ID: \n{response.headers["x-oss-request-id"]}')
 
+    """
+    封面发送到art-pubbucket
+    """
+    @classmethod
+    def mp3_upload_oss(cls, src_url: str,
+                                video_id: str) -> Dict[str, Any]:
+        oss_object_key = f'jq_audio/audio/{video_id}.mp3'
+        auth = oss2.Auth(OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET)
+        bucket = oss2.Bucket(auth, OSS_BUCKET_ENDPOINT, "art-crawler")
+        response = bucket.put_object_from_file(oss_object_key, src_url)
+
+        if 'Content-Length' in response.headers:
+            return {
+                'status': response.status,
+                'oss_object_key': oss_object_key,
+                'save_oss_timestamp': int(datetime.now().timestamp() * 1000),
+            }
+        raise AssertionError(f'OSS上传失败,请求ID: \n{response.headers["x-oss-request-id"]}')
+
 
     @classmethod
     def download_video_oss(cls, video_url, video_path_url, v_id):

+ 68 - 25
common/tts_help.py

@@ -12,49 +12,92 @@ from common import Material, Feishu
 
 
 class TTS:
-
     @classmethod
     def get_pw_zm(cls, text):
         max_retries = 3
         for attempt in range(max_retries):
-            token = Material.get_cookie_data("KsoMsyP2ghleM9tzBfmcEEXBnXg", "U1gySe", "硅语")
-            url = "https://zh.api.guiji.cn/avatar2c/tool/sec_tts"
+            # token = Material.get_cookie_data("KsoMsyP2ghleM9tzBfmcEEXBnXg", "U1gySe", "硅语")
+            url = "https://videopre.piaoquantv.com/longvideoapi/producevideo/listeningTextSpeech"
 
-            payload = json.dumps({
+            payload = {
+                "machineCode": "fd5287b1-ccde-46db-8068-e50a58231a1a",
+                "appType": "8",
+                "produceVoiceConfigJson": '{"voice":"stanley","channel":"aliyun","speechRate":0,"pitchRate":0,"volume":100}',
                 "text": text,
-                "speaker_id": "160"
-            })
+                "versionName": "2.5.2",
+                "buildCode": "38",
+                "versionCode": "38",
+                "token": "9396f509996e4575a7733f59604719efec6fde7a"
+            }
+
             headers = {
-                'accept': 'application/json, text/plain, */*',
-                'content-type': 'application/json',
-                'cookie': 'anylangIsLogin=true',
-                'origin': 'https://app.guiji.cn',
-                'pragma': 'no-cache',
-                'referer': 'https://app.guiji.cn/',
-                'token': token
+                'Cookie': 'JSESSIONID=1204A84BECB3CB8AD3FDF765E57E2942'
             }
-            wait_time = random.uniform(5, 20)
+
+
+            wait_time = random.uniform(1, 10)
             time.sleep(wait_time)
             try:
-                proxies = {
-                    "http": "http://t10952018781111:1ap37oc3@d844.kdltps.com:15818",
-                    "https": "http://t10952018781111:1ap37oc3@d844.kdltps.com:15818"
-                }
-                response = requests.request("POST", url, headers=headers, data=payload, proxies=proxies)
+                response = requests.request("POST", url, headers=headers, data=payload)
                 response = response.json()
                 code = response["code"]
-                if code == 200:
+                if code == 0:
                     mp3 = response["data"]
                     return mp3
                 else:
                     if attempt == max_retries - 1:
-                        Feishu.bot("zhangyong", '机器自动改造消息通知', f'硅语错误请排查', '张勇')
+                        Feishu.bot("zhangyong", '机器自动改造消息通知', f'获取字幕音频cookie过期,请及时更换', '张勇')
                         return None
             except Exception:
                 if attempt == max_retries - 1:
-                    Feishu.bot("zhangyong", '机器自动改造消息通知', f'硅语错误请排查', '张勇')
+                    Feishu.bot("zhangyong", '机器自动改造消息通知', f'获取字幕音频cookie过期,请及时更换', '张勇')
                     return None
-        Feishu.bot("zhangyong", '机器自动改造消息通知', f'硅语cookie过期,请及时更换', '张勇')
+        Feishu.bot("zhangyong", '机器自动改造消息通知', f'获取字幕音频cookie过期,请及时更换', '张勇')
+
+
+
+    # @classmethod
+    # def get_pw_zm(cls, text):
+    #     max_retries = 3
+    #     for attempt in range(max_retries):
+    #         token = Material.get_cookie_data("KsoMsyP2ghleM9tzBfmcEEXBnXg", "U1gySe", "硅语")
+    #         url = "https://zh.api.guiji.cn/avatar2c/tool/sec_tts"
+    #
+    #         payload = json.dumps({
+    #             "text": text,
+    #             "speaker_id": "160"
+    #         })
+    #         headers = {
+    #             'accept': 'application/json, text/plain, */*',
+    #             'content-type': 'application/json',
+    #             'cookie': 'anylangIsLogin=true',
+    #             'origin': 'https://app.guiji.cn',
+    #             'pragma': 'no-cache',
+    #             'referer': 'https://app.guiji.cn/',
+    #             'token': token
+    #         }
+    #         wait_time = random.uniform(5, 20)
+    #         time.sleep(wait_time)
+    #         try:
+    #             proxies = {
+    #                 "http": "http://t10952018781111:1ap37oc3@d844.kdltps.com:15818",
+    #                 "https": "http://t10952018781111:1ap37oc3@d844.kdltps.com:15818"
+    #             }
+    #             response = requests.request("POST", url, headers=headers, data=payload, proxies=proxies)
+    #             response = response.json()
+    #             code = response["code"]
+    #             if code == 200:
+    #                 mp3 = response["data"]
+    #                 return mp3
+    #             else:
+    #                 if attempt == max_retries - 1:
+    #                     Feishu.bot("zhangyong", '机器自动改造消息通知', f'硅语错误请排查', '张勇')
+    #                     return None
+    #         except Exception:
+    #             if attempt == max_retries - 1:
+    #                 Feishu.bot("zhangyong", '机器自动改造消息通知', f'硅语错误请排查', '张勇')
+    #                 return None
+    #     Feishu.bot("zhangyong", '机器自动改造消息通知', f'硅语cookie过期,请及时更换', '张勇')
 
     """
     音频下载到本地
@@ -217,8 +260,8 @@ if __name__ == '__main__':
     # ]
     # subprocess.run(command)
     # print("完成")
-    video_file = '"千钧"中的“钧”是古代的一种重量单位,1钧等于30斤。因此,“千钧”就是1000钧,等于30,000斤。'
-    TTS.get_pw_zm(video_file)
+    video_file = 'http://clipres.yishihui.com/longvideo/material/voice/pre/20240820/3f930929584e4af8b7c2d1552536ac891724162309557'
+    TTS.getSrt(video_file)
     # result = subprocess.run(
     #     ["ffprobe", "-v", "error", "-show_entries", "format=duration",
     #      "-of", "default=noprint_wrappers=1:nokey=1", video_file],

+ 6 - 1
video_rewriting/video_processor.py

@@ -357,11 +357,16 @@ class VideoProcessor:
         if video_ending == "AI片尾引导":
             pw_srt_text = GPT4o.get_ai_pw(old_title)
             if pw_srt_text:
+
                 pw_url = TTS.get_pw_zm(pw_srt_text)
                 if pw_url:
                     pw_mp3_path = TTS.download_mp3(pw_url, video_path_url, pw_random_id)
+                    oss_mp3_key = Oss.mp3_upload_oss(pw_mp3_path, pw_random_id)
+                    oss_mp3_key = oss_mp3_key.get("oss_object_key")
+                    new_pw_path = f"http://art-crawler.oss-cn-hangzhou.aliyuncs.com/{oss_mp3_key}"
+                    print(f"mp3地址:{new_pw_path}")
                     # pw_url_sec = FFmpeg.get_video_duration(pw_mp3_path)
-                    pw_srt = TTS.getSrt(pw_url)
+                    pw_srt = TTS.getSrt(new_pw_path)
                     Common.logger(mark).info(f"{name}的{task_mark}下的视频{url},获取AI片尾srt成功")
                 else:
                     Feishu.bot(mark, 'TTS获取失败提示', f'无法获取到片尾音频,及时更换token', "张勇")