createVoiceTtsJobs.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. require dirname(__FILE__, 2) . '/vendor/autoload.php';
  3. $secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
  4. $secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
  5. $region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
  6. $cosClient = new Qcloud\Cos\Client(
  7. array(
  8. 'region' => $region,
  9. 'scheme' => 'https', // 万象接口必须使用https
  10. 'credentials'=> array(
  11. 'secretId' => $secretId,
  12. 'secretKey' => $secretKey)));
  13. try {
  14. // 提交一个语音合成任务 https://cloud.tencent.com/document/product/460/84797
  15. // 1. 使用模版
  16. $result = $cosClient->createVoiceTtsJobs(array(
  17. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  18. 'Tag' => 'Tts', // 固定为 Tts
  19. 'Operation' => array(
  20. 'TemplateId' => 't1460606b9752148c4ab182f55163ba7cd',
  21. 'TtsConfig' => array(
  22. 'InputType' => 'Text',
  23. 'Input' => '床前明月光,疑是地上霜',
  24. ),
  25. 'Output' => array(
  26. 'Region' => $region,
  27. 'Bucket' => 'examplebucket-125000000',
  28. 'Object' => 'demo.mp3',
  29. ),
  30. // 'UserData' => 'xxx',
  31. // 'JobLevel' => '0',
  32. ),
  33. // 'CallBack' => '',
  34. // 'CallBackFormat' => '',
  35. // 'CallBackType' => '',
  36. // 'CallBackMqConfig' => array(
  37. // 'MqRegion' => '',
  38. // 'MqMode' => '',
  39. // 'MqName' => '',
  40. // ),
  41. ));
  42. // 请求成功
  43. print_r($result);
  44. // 2. 自定义参数
  45. $result = $cosClient->createVoiceTtsJobs(array(
  46. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  47. 'Tag' => 'Tts', // 固定为 Tts
  48. 'Operation' => array(
  49. 'TtsConfig' => array(
  50. 'InputType' => 'Text',
  51. 'Input' => '床前明月光,疑是地上霜',
  52. ),
  53. 'TtsTpl' => array(
  54. 'Mode' => 'Sync',
  55. 'Codec' => 'pcm',
  56. 'VoiceType' => 'aixiaoxing',
  57. 'Volume' => '2',
  58. 'Speed' => '200',
  59. 'Emotion' => 'arousal',
  60. ),
  61. 'Output' => array(
  62. 'Region' => $region,
  63. 'Bucket' => 'examplebucket-125000000',
  64. 'Object' => 'demo.mp3',
  65. ),
  66. // 'UserData' => 'xxx',
  67. // 'JobLevel' => '0',
  68. ),
  69. // 'CallBack' => '',
  70. // 'CallBackFormat' => '',
  71. // 'CallBackType' => '',
  72. // 'CallBackMqConfig' => array(
  73. // 'MqRegion' => '',
  74. // 'MqMode' => '',
  75. // 'MqName' => '',
  76. // ),
  77. ));
  78. // 请求成功
  79. print_r($result);
  80. } catch (\Exception $e) {
  81. // 请求失败
  82. echo($e);
  83. }