duangu9666 2019-04-29 12:21
浏览 119

运行谷歌文本上给出的php脚本到语音api文档页面会出现错误“无法创建资源”

I am running the php code provided on the documentation page of text-to-api page. After running every 8-10 times successfuly. It gives me 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

It gives me error where on this line


$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);

I want to output the result error free every time I run this code.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?