baiduAip.php 802 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/5/24 20:39
  5. */
  6. namespace common\components;
  7. use Yii;
  8. use AipSpeech;
  9. class baiduAip
  10. {
  11. //transfer
  12. public static function transfer($text,$spd=5,$per=0)
  13. {
  14. try{
  15. $client = self::getClient();
  16. $res = $client->synthesis($text,'zh',1,[
  17. 'spd'=>$spd,
  18. 'per'=>$per,
  19. ]);
  20. return $res;
  21. }catch (\Exception $exception){
  22. }
  23. return false;
  24. }
  25. public static function getClient()
  26. {
  27. $appId = Yii::$app->params['baiduAipAppId'];
  28. $appKey = Yii::$app->params['baiduAipAppKey'];
  29. $appSecret = Yii::$app->params['baiduAipAppSecret'];
  30. $client = new AipSpeech($appId,$appKey,$appSecret);
  31. return $client;
  32. }
  33. }