|
@@ -7,6 +7,7 @@ use App\Facade\Site;
|
|
|
use App\Libs\Utils;
|
|
|
use GuzzleHttp\Client;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
use OSS\Core\OssException;
|
|
|
use OSS\OssClient;
|
|
@@ -253,4 +254,138 @@ class TimbreService
|
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
|
]);
|
|
|
}
|
|
|
+
|
|
|
+ public function emotionGroupList($data) {
|
|
|
+ $group_name = getProp($data, 'group_name');
|
|
|
+ $label = getProp($data, 'label');
|
|
|
+
|
|
|
+ $query = DB::table('mp_emotion_groups')->where('is_enabled', 1)->select('*');
|
|
|
+
|
|
|
+ if ($group_name) {
|
|
|
+ $query->where('group_name', 'like', "%{$group_name}%");
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($label) {
|
|
|
+ $query->where('label', 'like', $label);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $query->orderBy('id')->paginate();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addEmotionGroup($data) {
|
|
|
+ $group_name = getProp($data, 'group_name');
|
|
|
+ if (DB::table('mp_emotion_groups')->where('group_name', $group_name)->value('id')) Utils::throwError('20003:该组名已存在');
|
|
|
+ // 获取所有情感
|
|
|
+ $emotion_list = DB::table('mp_emotion_list')->where('is_enabled', 1)->pluck('emotion_name', 'emotion_code')->toArray();
|
|
|
+ $emotion_list = array_flip($emotion_list);
|
|
|
+
|
|
|
+ // 获取音色支持情感
|
|
|
+ $timbre_emotion = DB::table('mp_timbres')->where('timbre_type', getProp($data, 'voice_type'))->value('emotion');
|
|
|
+ $timbre_emotion = explode(',', $timbre_emotion);
|
|
|
+ $emotion = getProp($data, 'emotion');
|
|
|
+ if (!in_array($emotion, $timbre_emotion)) $emotion = '中性';
|
|
|
+ $emotion_type = isset($emotion_list[$emotion]) ? $emotion_list[$emotion] : 'neutral';
|
|
|
+
|
|
|
+ // 给一个默认文案
|
|
|
+ $text = '试听这段由专业团队打造的声音杰作。从角色塑造到环境音效,每个元素都经过反复推敲,只为给你带来最完美的听觉体验。';
|
|
|
+ $list = [
|
|
|
+ 'group_name' => $group_name,
|
|
|
+ // 'text' => trim(getProp($data, 'text')),
|
|
|
+ 'text' => $text,
|
|
|
+ 'emotion' => $emotion,
|
|
|
+ 'emotion_type' => $emotion_type,
|
|
|
+ 'voice_type' => getProp($data, 'voice_type'),
|
|
|
+ 'voice_name' => getProp($data, 'voice_name'),
|
|
|
+ 'speed_ratio' => getProp($data, 'speed_ratio', 0),
|
|
|
+ 'loudness_ratio'=> getProp($data, 'loudness_ratio', 0),
|
|
|
+ 'emotion_scale' => getProp($data, 'emotion_scale', 4),
|
|
|
+ 'pitch' => getProp($data, 'pitch', 0),
|
|
|
+ 'generate_status' => '制作中',
|
|
|
+ 'error_msg' => '',
|
|
|
+ 'created_at' => date('Y-m-d H:i:s'),
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ];
|
|
|
+
|
|
|
+ $id = DB::table('mp_emotion_groups')->insertGetId($list);
|
|
|
+ $boolen = $id ? true : false;
|
|
|
+
|
|
|
+ // if ($boolen) {
|
|
|
+ // $boolen = false;
|
|
|
+ // $client = new Client(['timeout' => 300, 'verify' => false]);
|
|
|
+ // // 根据ID通过API通知合成音频
|
|
|
+ // // $result = $client->get("http://47.240.171.155:5000/api/previewTask?taskId={$id}");
|
|
|
+ // $result = $client->get("http://122.9.129.83:5000/api/previewTask?taskId={$id}");
|
|
|
+ // $response = $result->getBody()->getContents();
|
|
|
+ // $response_arr = json_decode($response, true);
|
|
|
+ // if (!isset($response_arr['code']) || (int)$response_arr['code'] !== 0) {
|
|
|
+ // $error_msg = isset($response_arr['msg']) ? $response_arr['msg'] : '未知错误';
|
|
|
+ // Log::info('通知火山生成段落音频失败: '.$error_msg);
|
|
|
+ // Utils::throwError('20003:通知火山生成段落音频失败');
|
|
|
+ // }
|
|
|
+ // $boolen = true;
|
|
|
+ // }
|
|
|
+
|
|
|
+ return $boolen;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function editEmotionGroup($data) {
|
|
|
+ $group_id = getProp($data, 'group_id');
|
|
|
+ $group_name = getProp($data, 'group_name');
|
|
|
+ $tmp_group_id = DB::table('mp_emotion_groups')->where('group_name', $group_name)->value('id');
|
|
|
+ if ($tmp_group_id && $tmp_group_id != $group_id) Utils::throwError('20003:该音色组已存在');
|
|
|
+ // 获取所有情感
|
|
|
+ $emotion_list = DB::table('mp_emotion_list')->where('is_enabled', 1)->pluck('emotion_name', 'emotion_code')->toArray();
|
|
|
+ $emotion_list = array_flip($emotion_list);
|
|
|
+
|
|
|
+ // 获取音色支持情感
|
|
|
+ $timbre_emotion = DB::table('mp_timbres')->where('timbre_type', getProp($data, 'voice_type'))->value('emotion');
|
|
|
+ $timbre_emotion = explode(',', $timbre_emotion);
|
|
|
+ $emotion = getProp($data, 'emotion');
|
|
|
+ if (!in_array($emotion, $timbre_emotion)) $emotion = '中性';
|
|
|
+ $emotion_type = isset($emotion_list[$emotion]) ? $emotion_list[$emotion] : 'neutral';
|
|
|
+
|
|
|
+ $list = [
|
|
|
+ 'group_name' => $group_name,
|
|
|
+ // 'text' => trim(getProp($data, 'text')),
|
|
|
+ 'emotion' => $emotion,
|
|
|
+ 'emotion_type' => $emotion_type,
|
|
|
+ 'voice_type' => getProp($data, 'voice_type'),
|
|
|
+ 'voice_name' => getProp($data, 'voice_name'),
|
|
|
+ 'speed_ratio' => getProp($data, 'speed_ratio', 0),
|
|
|
+ 'loudness_ratio'=> getProp($data, 'loudness_ratio', 0),
|
|
|
+ 'emotion_scale' => getProp($data, 'emotion_scale', 4),
|
|
|
+ 'pitch' => getProp($data, 'pitch', 0),
|
|
|
+ 'generate_status' => '制作中',
|
|
|
+ 'error_msg' => '',
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ];
|
|
|
+
|
|
|
+ $boolen = DB::table('mp_emotion_groups')->where('id', $group_id)->update($list);
|
|
|
+
|
|
|
+ // if ($boolen) {
|
|
|
+ // $boolen = false;
|
|
|
+ // $client = new Client(['timeout' => 300, 'verify' => false]);
|
|
|
+ // // 根据ID通过API通知合成音频
|
|
|
+ // // $result = $client->get("http://47.240.171.155:5000/api/previewTask?taskId={$group_id}");
|
|
|
+ // $result = $client->get("http://122.9.129.83:5000/api/previewTask?taskId={$group_id}");
|
|
|
+ // $response = $result->getBody()->getContents();
|
|
|
+ // $response_arr = json_decode($response, true);
|
|
|
+ // if (!isset($response_arr['code']) || (int)$response_arr['code'] !== 0) {
|
|
|
+ // $error_msg = isset($response_arr['msg']) ? $response_arr['msg'] : '未知错误';
|
|
|
+ // Log::info('通知火山生成段落音频失败: '.$error_msg);
|
|
|
+ // Utils::throwError('20003:通知火山生成段落音频失败');
|
|
|
+ // }
|
|
|
+ // $boolen = true;
|
|
|
+ // }
|
|
|
+
|
|
|
+ return $boolen;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function delEmotionGroup($data) {
|
|
|
+ $group_id = getProp($data, 'group_id');
|
|
|
+ return DB::table('mp_emotion_groups')->where('id', $group_id)->update([
|
|
|
+ 'is_enabled' => 0,
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+ }
|
|
|
}
|