diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index 4f7373a9e..aca8a6ca7 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -1395,7 +1395,9 @@ class DialogController extends AbstractController 'prompt' => "将此语音识别为“" . Doo::getLanguages($language) . "”。", ]; } - $result = AI::transcriptions($recordData['file'], $extParams); + $result = AI::transcriptions($recordData['file'], $extParams, [ + 'accept-language' => Request::header('Accept-Language', 'zh') + ]); if (Base::isError($result)) { return $result; } @@ -1988,7 +1990,9 @@ class DialogController extends AbstractController } WebSocketDialog::checkDialog($msg->dialog_id); // - $result = AI::transcriptions(public_path($msgData['path'])); + $result = AI::transcriptions(public_path($msgData['path']), [], [ + 'accept-language' => Request::header('Accept-Language', 'zh') + ]); if (Base::isError($result)) { return $result; } diff --git a/app/Module/AI.php b/app/Module/AI.php index d472b2645..bfbe7c8fa 100644 --- a/app/Module/AI.php +++ b/app/Module/AI.php @@ -140,10 +140,11 @@ class AI * 通过 openAI 语音转文字 * @param string $filePath 语音文件路径 * @param array $extParams 扩展参数 + * @param array $extHeaders 扩展请求头 * @param bool $noCache 是否禁用缓存 * @return array */ - public static function transcriptions($filePath, $extParams = [], $noCache = false) + public static function transcriptions($filePath, $extParams = [], $extHeaders = [], $noCache = false) { if (!file_exists($filePath)) { return Base::retError("语音文件不存在"); @@ -158,14 +159,14 @@ class AI return Base::retError("请先在 AI 设置中配置 OpenAI 语音模型"); } - $result = Cache::remember($cacheKey, Carbon::now()->addDays(), function () use ($extParams, $filePath, $audioProvider) { + $result = Cache::remember($cacheKey, Carbon::now()->addDays(), function () use ($extParams, $extHeaders, $filePath, $audioProvider) { $post = array_merge($extParams, [ 'file' => new \CURLFile($filePath), 'model' => 'whisper-1', ]); - $header = [ + $header = array_merge($extHeaders, [ 'Content-Type' => 'multipart/form-data', - ]; + ]); $ai = new self($post, $header); $ai->setProvider($audioProvider);