baiduAip.php 828 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. 'aue'=>6,
  20. ]);
  21. return $res;
  22. }catch (\Exception $exception){
  23. }
  24. return false;
  25. }
  26. public static function getClient()
  27. {
  28. $appId = Yii::$app->params['baiduAipAppId'];
  29. $appKey = Yii::$app->params['baiduAipAppKey'];
  30. $appSecret = Yii::$app->params['baiduAipAppSecret'];
  31. $client = new AipSpeech($appId,$appKey,$appSecret);
  32. return $client;
  33. }
  34. }