PHPackages                             saviorlv/yii2-bd-aipspeech - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. saviorlv/yii2-bd-aipspeech

ActiveYii2-extension

saviorlv/yii2-bd-aipspeech
==========================

Yii2 百度 语音识别

1.0.0(7y ago)248MITPHPPHP &gt;=5.6

Since Jan 21Pushed 7y ago1 watchersCompare

[ Source](https://github.com/sunmking/yii2-bd-aipspeech)[ Packagist](https://packagist.org/packages/saviorlv/yii2-bd-aipspeech)[ RSS](/packages/saviorlv-yii2-bd-aipspeech/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

 saviorlv/yii2-bd-aipspeech
============================

[](#-saviorlvyii2-bd-aipspeech-)

 基于百度AI 的语音合成、转换的 Yii2 sdk.

安装
--

[](#安装)

```
$ composer require saviorlv/yii2-bd-aipspeech -vvv
```

配置
--

[](#配置)

```
  // 配置文件里修改
  '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. 语音转换

```
//请求
 $aipSpeech = Yii::$app->get('aipSpeech');
  $file = Yii::getAlias('@tmp'.'/audios/').'16k.pcm';
  $x = $aipSpeech->recognize($file,'');
   var_dump($x);
```

```
//响应
[
  'success' =>true,
  'msg' => '语音识别成功',
  'data' =>[
    ......
  ]
]
//or
[
  'success' =>false,
  'msg' => '语音文件路径错误',
]
```

> 2. 语音合成

```
//请求
 $aipSpeech = Yii::$app->get('aipSpeech');
 $x = $aipSpeech->combine('您好，世界');
  var_dump($x);
```

```
//响应
[
  'success' =>true,
  'msg' => '语音合成成功',
  'data' =>'/webwww/yii2-bd/tmp/audios/5c4575feeb70d.mp3'
]
//or
[
  'success' =>false,
  'msg' => '语音合成失败',
]
```

说明
--

[](#说明)

> 语音识别参数说明

### 用法

[](#用法)

```
/**
     * 语音识别
     *
     * @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参数见本节开头的表格 否  > 语音合成参数说明

### 用法

[](#用法-1)

```
/**
     * 语音合成
     *
     * @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){}
```

### 参数

[](#参数-1)

   参数 类型 描述 是否必须     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
-------

[](#license)

MIT

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2668d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c9ecc98eec8f6e243c91d53019ffa4d86dab5da58a89d3d23d1523ebe4fec5ea?d=identicon)[sunmking](/maintainers/sunmking)

---

Tags

aipbaiduspeechspeech-to-textyii2extensionspeechbaidu

### Embed Badge

![Health badge](/badges/saviorlv-yii2-bd-aipspeech/health.svg)

```
[![Health](https://phpackages.com/badges/saviorlv-yii2-bd-aipspeech/health.svg)](https://phpackages.com/packages/saviorlv-yii2-bd-aipspeech)
```

###  Alternatives

[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.6k47](/packages/skeeks-cms)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
