瀏覽代碼

剧本解析主体音色增加保底逻辑

lh 2 月之前
父節點
當前提交
24470eb13c
共有 1 個文件被更改,包括 76 次插入0 次删除
  1. 76 0
      app/Libs/Helpers.php

+ 76 - 0
app/Libs/Helpers.php

@@ -2579,6 +2579,44 @@ function handleEpisodeContent($originalContent) {
                         $roleData['voice_type'] = getProp($timbre, 'timbre_type');
                         $roleData['voice_audio_url'] = getProp($timbre, 'audio_url');;
                     }
+                }else {
+                    // 从描述或人物提示词中获取"男"或"女",赋予默认音色,获取不到则使用旁白音色
+                    if ($picPrompt) {
+                        if (strstr($picPrompt, '男')) {
+                            $roleData['voice_name'] = '阳光青年';
+                        }elseif (strstr($picPrompt, '女')) {
+                            $roleData['voice_name'] = '爽快思思';
+                        }else {
+                            if ($description) {
+                                if (strstr($description, '男')) {
+                                    $roleData['voice_name'] = '阳光青年';
+                                }elseif (strstr($description, '女')) {
+                                    $roleData['voice_name'] = '爽快思思';
+                                }else {
+                                    $roleData['voice_name'] = '旁白';
+                                }
+                            }
+                        }
+                    }
+
+                    if (!empty($roleData['voice_name'])) {
+                        if ($roleData['voice_name'] == '旁白') {
+                            $roleData['voice_type'] = 'zh_male_linjiananhai_moon_bigtts';
+                            $roleData['voice_audio_url'] = 'https://zw-audiobook.tos-cn-beijing.volces.com/demonstrate/zh_male_linjiananhai_moon_bigtts.wav';
+                        }else {
+                            $timbre = DB::table('mp_timbres')
+                                ->where('is_enabled', 1)
+                                ->where('timbre_name', 'like', "%".$roleData['voice_name']."%")
+                                ->orderBy('id')
+                                ->select('timbre_type', 'audio_url')
+                                ->first();
+
+                            if ($timbre) {
+                                $roleData['voice_type'] = getProp($timbre, 'timbre_type');
+                                $roleData['voice_audio_url'] = getProp($timbre, 'audio_url');
+                            }
+                        }
+                    }
                 }
                 
                 $result['roles'][] = $roleData;
@@ -3176,6 +3214,44 @@ function parseRolesFromText(string $rolesText): array
                     $roleData['voice_type'] = getProp($timbre, 'timbre_type');
                     $roleData['voice_audio_url'] = getProp($timbre, 'audio_url');
                 }
+            }else {
+                // 从描述或人物提示词中获取"男"或"女",赋予默认音色,获取不到则使用旁白音色
+                if ($picPrompt) {
+                    if (strstr($picPrompt, '男')) {
+                        $roleData['voice_name'] = '阳光青年';
+                    }elseif (strstr($picPrompt, '女')) {
+                        $roleData['voice_name'] = '爽快思思';
+                    }else {
+                        if ($description) {
+                            if (strstr($description, '男')) {
+                                $roleData['voice_name'] = '阳光青年';
+                            }elseif (strstr($description, '女')) {
+                                $roleData['voice_name'] = '爽快思思';
+                            }else {
+                                $roleData['voice_name'] = '旁白';
+                            }
+                        }
+                    }
+                }
+
+                if (!empty($roleData['voice_name'])) {
+                    if ($roleData['voice_name'] == '旁白') {
+                        $roleData['voice_type'] = 'zh_male_linjiananhai_moon_bigtts';
+                        $roleData['voice_audio_url'] = 'https://zw-audiobook.tos-cn-beijing.volces.com/demonstrate/zh_male_linjiananhai_moon_bigtts.wav';
+                    }else {
+                        $timbre = DB::table('mp_timbres')
+                            ->where('is_enabled', 1)
+                            ->where('timbre_name', 'like', "%".$roleData['voice_name']."%")
+                            ->orderBy('id')
+                            ->select('timbre_type', 'audio_url')
+                            ->first();
+
+                        if ($timbre) {
+                            $roleData['voice_type'] = getProp($timbre, 'timbre_type');
+                            $roleData['voice_audio_url'] = getProp($timbre, 'audio_url');
+                        }
+                    }
+                }
             }
 
             $roles[] = $roleData;