liunx系统 安装 ffmpeg
申请百度语音识别接口
/**
* 录音转文字
* @param Request $request
* @return mixed
*/
public function speech(Request $request){
// $path = Flysystem::put(111,$request->file('record'));
if(!$request->hasFile('record')) {
return new ResultService(RESULT_FAILED,'','没有录音文件');
}
$path = Storage::disk('local')->putFile('record', $request->file('record'));
$in = '/data/www/storage/app/'.$path;
// $in = '/data/www/storage/app/record/PHEy1oW6HKKNAhKzgLjlzhhceZFdJi5gAKW6YSLS.mpga';
$out = '/data/www/storage/app/record/'.time().'.wav';
$shell = "ffmpeg -i $in -y -f wav $out";
exec($shell,$file,$status);
try{
// echo file_get_contents($out);die;
$client = new AipSpeechService(env('BAIDU_APP_ID'), env('BAIDU_API_KEY'), env('BAIDU_SECRET_KEY'));
// 识别本地文件
$res = $client->asr(file_get_contents($out),'wav', 16000, array(
'dev_pid' => 1536,
));
if($res['err_no']==0){
return new ResultService(RESULT_SUCCESS,$res['result'][0]);
}else{
Log::debug(json_encode( $res));
return new ResultService(RESULT_FAILED,'','接口失败');
}
}catch (Exception $exception){
Log::debug(json_encode( $exception->getMessage()));
return new ResultService(RESULT_FAILED,'','转换失败');
}
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。