lh 4 天之前
父节点
当前提交
c145cfc02b
共有 1 个文件被更改,包括 13 次插入4 次删除
  1. 13 4
      app/Services/DeepSeek/DeepSeekService.php

+ 13 - 4
app/Services/DeepSeek/DeepSeekService.php

@@ -129,6 +129,15 @@ class DeepSeekService
             'error_msg'     => '',
             'updated_at'    => date('Y-m-d H:i:s')
         ];
+
+        $continue = false;
+        // 判断是否含有中文、数字或英文,如果没有则跳过合成
+        if (!preg_match('/[\x{4e00}-\x{9fa5}]+/u', $list['text']) && !preg_match('/[0-9]+/', $list['text']) && !preg_match('/[a-zA-Z]+/', $list['text'])) {
+            $list['generate_status'] = '制作成功';
+            $list['paragraph_audio_url'] = 'https://zw-audiobook.tos-cn-beijing.volces.com/effects/ellipses_2s.mp3';
+            $continue = true;
+        }
+
         // if (getProp($data, 'paragraph_audio_url')) $list['paragraph_audio_url'] = getProp($data, 'paragraph_audio_url');
         if ($id) {
             $boolen = DB::table('mp_chapter_paragraph_audios')->where('id', $id)->update($list);
@@ -138,7 +147,7 @@ class DeepSeekService
             $boolen = $id ? true : false;
         }
 
-        if ($boolen) {
+        if ($boolen && !$continue) {
             $boolen = false;
             $client = new Client(['timeout' => 300, 'verify' => false]);
             // 根据ID通过API通知合成音频
@@ -205,11 +214,11 @@ class DeepSeekService
             if (!($word['text']) || !($word['voice_type']) || !($word['voice_name'])) Utils::throwError('20003:参数不得为空');
             $role = getProp($word, 'role');
             $word['gender'] = (int)$word['gender'];
-            if (isset($emotion_list[getProp($word, 'emotion')])) {  // 如果有对应情感则赋值,没有则默认为自然讲述(storytelling)
+            if (isset($emotion_list[getProp($word, 'emotion')])) {  // 如果有对应情感则赋值,没有则默认为中性(neutral)
                 $word['emotion_type'] = $emotion_list[getProp($word, 'emotion')];
             }else {
-                $word['emotion'] = '自然讲述';
-                $word['emotion_type'] = 'storytelling';
+                $word['emotion'] = '中性';
+                $word['emotion_type'] = 'neutral';
             }
             if (!in_array($role, $existed_roles)) {
                 $existed_role_info[$role] = [