php - 运行谷歌文本到语音 api 文档页面上给出的 php 脚本会出现错误“无法创建资源”
问题描述
我正在运行 text-to-api 页面的文档页面上提供的 php 代码。每跑8-10次就成功了。它给了我
Error creating resource: [message] fopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known [file] /Desktop/php_projects/text_speech/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php [line] 323 [message] fopen(https://oauth2.googleapis.com/token): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known [file] /Desktop/php_projects/text_speech/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php [line] 323
它在这条线上给了我错误
$response = $client->synthesizeSpeech($synthesisInputText, $voice, $audioConfig);
require __DIR__ . '/vendor/autoload.php';
// Imports the Cloud Client Library
use Google\Cloud\TextToSpeech\V1\AudioConfig;
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
$client = new TextToSpeechClient([
'credentials' => ('/Documents/gcp_credentials/config.json')
]);
$synthesisInputText = (new SynthesisInput())
->setText('Hello, world! This is just for testing purpose.Lorem Ipsum is simply dummy text of the printing and typesetting industry.This is just for testing purpose.Lorem Ipsum is simply dummy text of the printing and typesetting industry');
$voice = (new VoiceSelectionParams())
->setLanguageCode('en-IN')
->setName('en-IN-Wavenet-A')
->setSsmlGender(SsmlVoiceGender::FEMALE);
$effectsProfileId = "telephony-class-application";
$audioConfig = (new AudioConfig())
->setAudioEncoding(AudioEncoding::LINEAR16)
->setEffectsProfileId(array($effectsProfileId));
$response = $client->synthesizeSpeech($synthesisInputText, $voice, $audioConfig);
$audioContent = $response->getAudioContent();
file_put_contents('output.wav', $audioContent);
每次运行此代码时,我都想无错误地输出结果。
解决方案
推荐阅读
- javascript - 如何概括从 Lens 到 Traversal 以及从 Getter 到 Fold optic?
- javascript - 如何增加 ScrollToBottom 以填充屏幕的高度?
- cdn - 如果用户收到 50* 错误,如何强制 Fastly CDN 将请求重定向到单独的域?
- google-chrome - 由于“IO 错误:.../000001.dbtmp:无法重命名文件:文件当前正在使用”,Chrome 扩展 Chrome.Storage 调用失败
- java - 为什么@ConfigurationProperties 需要getter?
- c - libdbus:从 DBusMessage 参数中获取字符串列表
- python - MySQL 服务器:使用 dask 连接
- python - 如何在我的 python 虚拟环境中设置 pytest
- python - sklearn 的 cross_val_score 的重现性
- html - 使用 HTML/CSS 样式化验证错误消息