Browse Source

增加多音频随机选

zhangyong 7 months ago
parent
commit
a7f1459754
3 changed files with 26 additions and 13 deletions
  1. 7 4
      common/feishu_form.py
  2. 5 5
      common/tts_help.py
  3. 14 4
      video_rewriting/video_processor.py

+ 7 - 4
common/feishu_form.py

@@ -69,13 +69,14 @@ class Material():
                 number = row[4]
                 video_share = row[5]
                 video_ending = row[6]
-                crop_tool = row[7]
-                gg_duration = row[8]
-                title = row[9]
+                voice = row[7]
+                crop_tool = row[8]
+                gg_duration = row[9]
+                title = row[10]
                 if channel_url == None or channel_url == "" or len(channel_url) == 0:
                     continue
                 try:
-                    ls_number = int(row[10])
+                    ls_number = int(row[11])
                 except:
                     ls_number = None
                 def count_items(item, separator):
@@ -105,6 +106,7 @@ class Material():
                             "video_ending": video_ending,
                             "crop_total": crop_tool,
                             "gg_duration_total": gg_duration,
+                            "voice": voice
                         }
                         processed_list.append(json.dumps(number_dict, ensure_ascii=False))
                         if channel_id == "抖音" or channel_id == "快手" or channel_id == "视频号":
@@ -131,6 +133,7 @@ class Material():
                                     "video_ending": video_ending,
                                     "crop_total": crop_tool,
                                     "gg_duration_total": gg_duration,
+                                    "voice": voice
                                 }
                                 processed_list.append(json.dumps(number_dict, ensure_ascii=False))
                 else:

+ 5 - 5
common/tts_help.py

@@ -13,14 +13,14 @@ from common import Material, Feishu
 
 class TTS:
     @classmethod
-    def get_pw_zm(cls, text):
+    def get_pw_zm(cls, text, voice):
         max_retries = 3
         for attempt in range(max_retries):
             url = "http://api.piaoquantv.com/produce-center/speechSynthesis"
             payload = json.dumps({
                 "params": {
                     "text": text,
-                    "voice": "zhifeng_emo",
+                    "voice": voice,
                     # "vocie": "zhiyuan",
                     "format": "pcm",
                     "volume": 90,
@@ -40,15 +40,15 @@ class TTS:
                 code = response["code"]
                 if code == 0:
                     mp3 = response["data"]
-                    return mp3
+                    return mp3, voice
                 else:
                     if attempt == max_retries - 1:
                         Feishu.bot("zhangyong", '机器自动改造消息通知', f'获取字幕音频失败,请关注', '张勇')
-                        return None
+                        return None, voice
             except Exception:
                 if attempt == max_retries - 1:
                     Feishu.bot("zhangyong", '机器自动改造消息通知', f'获取字幕音频失败,请关注', '张勇')
-                    return None
+                    return None, voice
         Feishu.bot("zhangyong", '机器自动改造消息通知', f'获取字幕音频失败,请关注', '张勇')
 
 

+ 14 - 4
video_rewriting/video_processor.py

@@ -85,6 +85,15 @@ class VideoProcessor:
         video_ending = task["video_ending"]
         crop_total = task["crop_total"]
         gg_duration_total = task["gg_duration_total"]
+        voice = task['voice']
+        if voice:
+            if ',' in voice:
+                voices = voice.split(',')
+            else:
+                voices = [voice]
+            voice = random.choice(voices)
+        else:
+            voice = "zhifeng_emo"
         video_path_url = cls.create_folders(mark, str(task_mark))
         zm = Material.get_pzsrt_data("summary", "500Oe0", video_share)
         Common.logger(mark).info(f"{name}的{task_mark}下{channel_id}的用户:{url}开始获取视频")
@@ -148,7 +157,7 @@ class VideoProcessor:
                     continue
                 if new_video_path:
                     if video_ending and video_ending != 'None':
-                        new_video_path = cls.handle_video_ending(new_video_path, video_ending, old_title, pw_random_id, video_path_url, mark, task_mark, url, name, video_share, zm)
+                        new_video_path = cls.handle_video_ending(new_video_path, video_ending, old_title, pw_random_id, video_path_url, mark, task_mark, url, name, video_share, zm, voice)
                     else:
                         if video_share and video_share != 'None':
                             new_video_path = FFmpeg.single_video(new_video_path, video_path_url, zm)
@@ -199,13 +208,14 @@ class VideoProcessor:
                         f"**渠道**: {channel_id}\n"
                         f"**视频主页ID**: {url}\n"
                         f"**视频Video_id**: {v_id}\n"
+                        f"**使用音频音色**: {voice}\n"
                     )
 
 
                     Feishu.finish_bot(text,
                                       "https://open.feishu.cn/open-apis/bot/v2/hook/e7697dc6-5254-4411-8b59-3cd0742bf703",
                                       "【 机器改造通知 】")
-                    log_data = f"user:{url},video_id:{v_id},video_url:{video_url},ai_title:{new_title}"
+                    log_data = f"user:{url},video_id:{v_id},video_url:{video_url},ai_title:{new_title},voice:{voice}"
                     AliyunLogger.logging(channel_id, name, url, v_id, "视频改造成功", "1000", log_data, str(code))
                     if channel_id == "快手历史" or channel_id == "抖音历史" or channel_id == "视频号历史":
                         explain = "历史爆款"
@@ -360,7 +370,7 @@ class VideoProcessor:
             return new_video_path
 
     @classmethod
-    def handle_video_ending(cls, new_video_path, video_ending, old_title, pw_random_id, video_path_url, mark, task_mark, url, name, video_share, zm):
+    def handle_video_ending(cls, new_video_path, video_ending, old_title, pw_random_id, video_path_url, mark, task_mark, url, name, video_share, zm, voice):
         """
         处理视频片尾
         """
@@ -368,7 +378,7 @@ class VideoProcessor:
             pw_srt_text = GPT4o.get_ai_pw(old_title)
             if pw_srt_text:
 
-                pw_url = TTS.get_pw_zm(pw_srt_text)
+                pw_url = TTS.get_pw_zm(pw_srt_text, voice)
                 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)