最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Unable to perform long audio synthesis. Neither the client project number: 863017906842 nor ID: project-219819 matches the

programmeradmin0浏览0评论

I am trying to generate long audio from text with the Google text-to-speech api, using the google/cloud-text-to-speech PHP client.

I have created the Service Account and given it the permissions in the bucket, as explained in all two links

/

/

The PHP code I use is as follows:

require_once 'vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=C:\Users\Name\Projects\google-text-to-speech\project-219819-da3fdd6a76ad.json');

use Google\Cloud\TextToSpeech\V1\AudioConfig;
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechLongAudioSynthesizeClient;
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
use Google\Cloud\TextToSpeech\V1\SynthesizeLongAudioRequest;
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;

try {

    $client = new TextToSpeechLongAudioSynthesizeClient();

    $synthesisInputText = (new SynthesisInput())
        ->setText('Hola, ¿cómo estás? gracias por venir.');

    $voice = (new VoiceSelectionParams())
        ->setLanguageCode('es-ES')
        ->setName('es-ES-Standard-A')
        ->setSsmlGender(SsmlVoiceGender::FEMALE);    
        
    $effectsProfileId = 'handset-class-device';    
    
    $audioConfig = (new AudioConfig())
        ->setAudioEncoding(AudioEncoding::LINEAR16)
        ->setSpeakingRate(0.75)
        ->setEffectsProfileId(array($effectsProfileId));

    $request = (new SynthesizeLongAudioRequest())
        ->setParent('projects/project/locations/global')
        ->setOutputGcsUri('gs://bucket/audios/ejemplo.mp3')
        ->setInput($synthesisInputText)
        ->setVoice($voice)
        ->setAudioConfig($audioConfig);
    $response = $client->synthesizeLongAudio($request);
    $audioContent = $response->getAudioContent();                   

    file_put_contents('output-long.mp3', $audioContent);
    echo '<audio src="output.mp3" controls />' . PHP_EOL;
    
    $textToSpeechClient->close();
} catch(Exception $e) {
    echo $e->getMessage();
}

But when I run it I get the following error

{ "message": "Unable to perform long audio synthesis. Neither the client project number: 863009906802 nor ID: project-219819 matches the resource project: bucket", "code": 3, "status": "INVALID_ARGUMENT", "details": [] }

Any ideas?

I am trying to generate long audio from text with the Google text-to-speech api, using the google/cloud-text-to-speech PHP client.

I have created the Service Account and given it the permissions in the bucket, as explained in all two links

https://angnasution/2023/07/long-audio-api-for-google-cloud-text-to-speech/

https://angnasution/2023/07/using-google-cloud-text-to-speech-api-with-python/

The PHP code I use is as follows:

require_once 'vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=C:\Users\Name\Projects\google-text-to-speech\project-219819-da3fdd6a76ad.json');

use Google\Cloud\TextToSpeech\V1\AudioConfig;
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechLongAudioSynthesizeClient;
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
use Google\Cloud\TextToSpeech\V1\SynthesizeLongAudioRequest;
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;

try {

    $client = new TextToSpeechLongAudioSynthesizeClient();

    $synthesisInputText = (new SynthesisInput())
        ->setText('Hola, ¿cómo estás? gracias por venir.');

    $voice = (new VoiceSelectionParams())
        ->setLanguageCode('es-ES')
        ->setName('es-ES-Standard-A')
        ->setSsmlGender(SsmlVoiceGender::FEMALE);    
        
    $effectsProfileId = 'handset-class-device';    
    
    $audioConfig = (new AudioConfig())
        ->setAudioEncoding(AudioEncoding::LINEAR16)
        ->setSpeakingRate(0.75)
        ->setEffectsProfileId(array($effectsProfileId));

    $request = (new SynthesizeLongAudioRequest())
        ->setParent('projects/project/locations/global')
        ->setOutputGcsUri('gs://bucket/audios/ejemplo.mp3')
        ->setInput($synthesisInputText)
        ->setVoice($voice)
        ->setAudioConfig($audioConfig);
    $response = $client->synthesizeLongAudio($request);
    $audioContent = $response->getAudioContent();                   

    file_put_contents('output-long.mp3', $audioContent);
    echo '<audio src="output.mp3" controls />' . PHP_EOL;
    
    $textToSpeechClient->close();
} catch(Exception $e) {
    echo $e->getMessage();
}

But when I run it I get the following error

{ "message": "Unable to perform long audio synthesis. Neither the client project number: 863009906802 nor ID: project-219819 matches the resource project: bucket", "code": 3, "status": "INVALID_ARGUMENT", "details": [] }

Any ideas?

Share Improve this question edited Nov 19, 2024 at 22:34 Doug Stevenson 318k36 gold badges455 silver badges473 bronze badges Recognized by Google Cloud Collective asked Nov 19, 2024 at 20:50 grankangrankan 4851 gold badge4 silver badges7 bronze badges 1
  • On Stack Overflow, don't answer your question within your own post. Post an answer just like anyone else, and accept it as correct so it's perfectly clear to future readers what the solution is. I've edited the question to remove the answer, now please post your answer correctly. – Doug Stevenson Commented Nov 19, 2024 at 22:34
Add a comment  | 

1 Answer 1

Reset to default 0

As per the error, you need to use the project ID, see the BOLD part below:

$request = (new SynthesizeLongAudioRequest()) -\>setParent('projects/PROJECT ID/locations/global') -\>setOutputGcsUri('gs://bucket/audios/ejemplo.mp3') -\>setInput($synthesisInputText) -\>setVoice($voice) -\>setAudioConfig($audioConfig);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论