From 7a6bbfac755e9a779d86220d54a17658fd01a3b6 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sun, 9 Nov 2025 04:43:17 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0AI=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84transcriptions=E6=96=B9=E6=B3=95=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=89=A9=E5=B1=95=E8=AF=B7=E6=B1=82=E5=A4=B4=E5=8F=82?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E4=BC=98=E5=8C=96=E8=AF=AD=E9=9F=B3=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/DialogController.php | 8 ++++++-- app/Module/AI.php | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) 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);