pinkong/baidu-speech-recognition

封装百度语音识别API,适用于Laravel和Lumen应用程序

1.0 2018-04-16 03:08 UTC

This package is not auto-updated.

Last update: 2024-09-29 06:02:30 UTC


README

这个Laravel\Lumen扩展包使用百度云语音识别API,提供了一种简单的方法从语音文件中提取文本。代码基于官方php sdk构建。

在开始使用之前,请先访问百度AI开放平台,找到“人工智能”下的“百度语音”,创建应用。 百度的语言识别API是免费的,默认每天有50000次调用限制,如有需要,可以申请将配额提高到每天1000000次。

由于百度的API只接受特定码率的文件,所以代码中使用了ffmepg进行转码。 因此需要注意以下几点:

  • 本地必须安装ffmepg
  • PHP必须有shell_exec执行权限

先决条件

要使用此包,您应该访问,找到人工智能->百度语音并创建一个应用,然后获取AppID、API Key和Secret Key。

安装

使用以下命令通过Composer安装此包

$ composer require pinkong/baidu-speech-recognition

然后,添加服务提供者

如果您使用Laravel,将服务提供者添加到config/app.php文件中的providers数组

[
    'providers' => [
        Pinkong\BaiduSpeechRecognition\BaiduSpeechServiceProvider::class,
    ],
]

可选:您可以使用外观

    'aliases' => [
        'SpeechHelper' => Pinkong\BaiduSpeechRecognition\SpeechHelper::class,
    ],

如果您使用Lumen,将以下代码追加到bootstrap/app.php

$app->register(Pinkong\BaiduSpeechRecognition\BaiduSpeechServiceProvider::class);

配置

默认值设置在config/baiduspeech.php中。 将此文件复制到您的config目录以修改值。 您可以使用以下命令发布配置

php artisan vendor:publish --provider="Pinkong\BaiduSpeechRecognition\BaiduSpeechServiceProvider"

如果您使用Lumen,将以下代码追加到bootstrap/app.php

$app->configure('baiduspeech');

用法

$result = SpeechHelper::convertMp3FileToPCM('test4.mp3');

许可

Laravel-Swoole-Http包是开源软件,采用MIT许可