Выполнение сценария php, указанного на странице документации API Google Text to Speech, приводит к ошибке «Не удается создать ресурс» - PullRequest
1 голос
/ 29 апреля 2019

Я использую код php, указанный на странице документации на странице text-to-api. После запуска каждые 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);

Я хочу выводить результат без ошибок при каждом запуске этого кода.

...