lh há 3 meses atrás
pai
commit
53613d7ba1

+ 18 - 0
app/Services/Book/BookService.php

@@ -281,7 +281,25 @@ class BookService
         $result = DB::table('mp_audio_tasks')->where('id', $task_id)->select('id as task_id', 'task_name', 'generate_status', 'generate_json', 'bid', 'version_id', 'cid')->first();
         if (!$result) Utils::throwError('20003:任务不存在');
         $result = (array)$result;
+        $paragraph_arr = DB::table('mp_chapter_paragraph_audios')->where('bid', $result['bid'])->where('version_id', $result['version_id'])->where('cid', $result['cid'])->get();
+        $list = [];
+        foreach ($paragraph_arr as $key => $value) {
+            $arr = (array)$value;
+            $list[$arr['sequence']] = $arr;
+        }
         $result['generate_json'] = json_decode($result['generate_json'], true);
+        foreach ($result['generate_json'] as $key => &$value) {
+            $sequence = getProp($value, 'sequence');
+            $arr = isset($list[$sequence]) ? $list[$sequence] : [];
+            if ($arr) {
+                $value['role'] = $arr['role'];
+                $value['text'] = $arr['text'];
+                $value['voice_type'] = $arr['voice_type'];
+                $value['speed_ratio'] = $arr['speed_ratio'];
+                $value['loudness_ratio'] = $arr['loudness_ratio'];
+                $value['emotion_scale'] = $arr['emotion_scale'];
+            }
+        }
 
         return $result;
     }

+ 15 - 7
app/Services/DeepSeek/DeepSeekService.php

@@ -438,6 +438,7 @@ class DeepSeekService
         // 最终合成前的参数组
         $mp_chapter_paragraph_audios = [];
         $sequence = 1;
+        $complete_paragraph_sequences = [];
         foreach($words as &$word) {
             if (!isset($word['text']) || !isset($word['emotion']) || !isset($word['voice_type']) || !isset($word['voice_name']) || !isset($word['speed_ratio']) || !isset($word['loudness_ratio']) || !isset($word['emotion_scale'])) Utils::throwError('20003:参数格式有误');
             if (!($word['text']) || !($word['voice_type']) || !($word['voice_name'])) Utils::throwError('20003:参数不得为空');
@@ -470,13 +471,14 @@ class DeepSeekService
             $paragraph = isset($paragraph_list[$sequence]) ? $paragraph_list[$sequence] : [];
             // 如果音频存在并且参数都未改变则使用已生成的音频
             if (getProp($paragraph, 'paragraph_audio_url')) {
-                if (getProp($paragraph, 'role') == getProp($word, 'role') && getProp($paragraph, 'text') == getProp($word, 'text') && 
-                    getProp($paragraph, 'voice_type') == getProp($word, 'voice_type') && 
-                    getProp($paragraph, 'speed_ratio') == getProp($word, 'speed_ratio') && getProp($paragraph, 'loudness_ratio') == getProp($word, 'loudness_ratio') &&
-                    getProp($paragraph, 'emotion_scale') == getProp($word, 'emotion_scale'))
-                {
-                        $word['paragraph_audio_url'] = getProp($paragraph, 'paragraph_audio_url');
-                }
+                // if (getProp($paragraph, 'role') == getProp($word, 'role') && getProp($paragraph, 'text') == getProp($word, 'text') && 
+                //     getProp($paragraph, 'voice_type') == getProp($word, 'voice_type') && 
+                //     getProp($paragraph, 'speed_ratio') == getProp($word, 'speed_ratio') && getProp($paragraph, 'loudness_ratio') == getProp($word, 'loudness_ratio') &&
+                //     getProp($paragraph, 'emotion_scale') == getProp($word, 'emotion_scale'))
+                // {
+                //         $word['paragraph_audio_url'] = getProp($paragraph, 'paragraph_audio_url');
+                // }
+                $word['paragraph_audio_url'] = getProp($paragraph, 'paragraph_audio_url');
             }
 
             $tmp = $word;
@@ -498,6 +500,7 @@ class DeepSeekService
             $tmp['updated_at'] = date('Y-m-d H:i:s');
             if (!getProp($tmp, 'paragraph_audio_url')) Utils::throwError('20003:段落未生成音频,请等待完成后提交');
             $mp_chapter_paragraph_audios[] = $tmp;
+            $complete_paragraph_sequences[] = $sequence;
 
             $sequence++;
         }
@@ -544,6 +547,11 @@ class DeepSeekService
                 Utils::throwError('20003:创建任务失败');
             }
 
+            // 删除不在段落序号范围内的其他数据
+            if ($complete_paragraph_sequences) {
+                DB::table('mp_chapter_paragraph_audios')->where('bid', $bid)->where('version_id', $version_id)->where('cid', $cid)->whereNotIn('sequence', $complete_paragraph_sequences)->delete();
+            }
+
             // // 删除章节分句音频数据并重新插入
             // DB::table('mp_chapter_paragraph_audios')->where('bid', $bid)->where('version_id', $version_id)->where('cid', $cid)->delete();
             // $boolen3 = DB::table('mp_chapter_paragraph_audios')->insert($mp_chapter_paragraph_audios);