mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 18:42:54 +00:00
feat: 更新AI模块的transcriptions方法,增加扩展请求头参数,优化语音识别功能
This commit is contained in:
parent
425d6f9a06
commit
7a6bbfac75
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user