https://github.com/sunmking/yii2-bd-aipspeech
yii2 百度云 aipspeech AI 语音识别
https://github.com/sunmking/yii2-bd-aipspeech
aip baidu speech speech-to-text
Last synced: over 1 year ago
JSON representation
yii2 百度云 aipspeech AI 语音识别
- Host: GitHub
- URL: https://github.com/sunmking/yii2-bd-aipspeech
- Owner: sunmking
- Created: 2019-01-21T02:46:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-21T08:02:50.000Z (over 7 years ago)
- Last Synced: 2025-01-22T07:23:03.806Z (over 1 year ago)
- Topics: aip, baidu, speech, speech-to-text
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
saviorlv/yii2-bd-aipspeech
基于百度AI 的语音合成、转换的 Yii2 sdk.
## 安装
```shell
$ composer require saviorlv/yii2-bd-aipspeech -vvv
```
## 配置
```php
// 配置文件里修改
'components' => [
......
'aipSpeech' => [
'class' => 'Saviorlv\Baidu\BdSpeech',
'app_id' => 'xxxxxx', // 百度语音 App ID
'api_key' => 'xxxxxxx', // 百度语音 API Key
'secret_key' => 'xxxxxx', // 百度语音 Secret Key
'path' => Yii::getAlias('@tmp'.'/audios/') //可以不填写 默认在 runtime
],
......
],
```
## 使用
> 1. 语音转换
```php
//请求
$aipSpeech = Yii::$app->get('aipSpeech');
$file = Yii::getAlias('@tmp'.'/audios/').'16k.pcm';
$x = $aipSpeech->recognize($file,'');
var_dump($x);
```
```php
//响应
[
'success' =>true,
'msg' => '语音识别成功',
'data' =>[
......
]
]
//or
[
'success' =>false,
'msg' => '语音文件路径错误',
]
```
> 2. 语音合成
```php
//请求
$aipSpeech = Yii::$app->get('aipSpeech');
$x = $aipSpeech->combine('您好,世界');
var_dump($x);
```
```php
//响应
[
'success' =>true,
'msg' => '语音合成成功',
'data' =>'/webwww/yii2-bd/tmp/audios/5c4575feeb70d.mp3'
]
//or
[
'success' =>false,
'msg' => '语音合成失败',
]
```
## 说明
> 语音识别参数说明
### 用法
```php
/**
* 语音识别
*
* @param $filePath string 语音文件本地路径,优先使用此项
* @param $url string 语音文件URL路径
* @param $userID string 用户唯一标识
* @param $format string 语音文件格式 ['pcm', 'wav', 'opus', 'speex', 'amr']
* @param $rate integer 采样率 [8000, 16000]
* @param $dev_pid int 语音语言 [1536,1537,1737,1637,1837,1936]
* @return array
*/
public function recognize($filePath, $url, $format = 'wav', $dev_pid = 1536, $userID = null, $rate = 16000)
{}
```
### 参数
参数
类型
描述
是否必须
$filePath
String
建立包含语音内容的本地, 语音文件的格式,pcm 或者 wav 或者 amr。不区分大小写
是(url 二选一)
$url
String
建立包含语音内容的url, 语音文件的格式,pcm 或者 wav 或者 amr。不区分大小写
是(filePath 二选一)
format
String
语音文件的格式,pcm 或者 wav 或者 amr。不区分大小写。推荐pcm文件
是
rate
int
采样率,16000,固定值
是
userId
String
用户唯一标识,用来区分用户,填写机器 MAC 地址或 IMEI 码,长度为60以内
否
dev_pid
Int
不填写lan参数生效,都不填写,默认1537(普通话 输入法模型),dev_pid参数见本节开头的表格
否
> 语音合成参数说明
### 用法
```php
/**
* 语音合成
*
* @param $text string 合成的文本
* @param $userID string 用户唯一标识
* @param $lan string 语音 ['zh']
* @param $speed integer 语速,取值0-9,默认为5中语速
* @param $pitch integer 音调,取值0-9,默认为5中语调
* @param $volume integer 音量,取值0-15,默认为5中音量
* @param $person integer 发音人选择, 0为女声,1为男声,3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女
* @param $fileName string 存储文件路径名称
* @return array
*/
public function combine($text, $userID = null, $lan = 'zh', $speed = 5, $pitch = 5, $volume = 5, $person = 0, $fileName = null){}
```
### 参数
参数
类型
描述
是否必须
tex
String
合成的文本,使用UTF-8编码,
请注意文本长度必须小于1024字节
是
userID
String
用户唯一标识,用来区分用户,
填写机器 MAC 地址或 IMEI 码,长度为60以内
否
speed
String
语速,取值0-9,默认为5中语速
否
pitch
String
音调,取值0-9,默认为5中语调
否
volume
String
音量,取值0-15,默认为5中音量
否
person
String
发音人选择, 0为女声,1为男声,
3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女
否
fileName
String
合成文件名称
否
lan
String
合成语音的语言 默认 zh
否
## 参考文件
[百度语音](http://ai.baidu.com/docs#/ASR-Online-PHP-SDK/top), 一定要先看文档
> 感谢
[e-yunduan/yii2-aip-speech](https://github.com/e-yunduan/yii2-aip-speech)
## License
MIT