Google Cloud Text-to-Speech on Apps Script App - Stack Overflow

admin2025-04-17  1

I'm encountering a persistent issue with granting the "Cloud Text-to-Speech Client" role to a service account in my Google Cloud project. I'm trying to use the Cloud Text-to-Speech API from a Google Apps Script project, but I keep getting a "Role roles/cloud.texttospeech.client is not supported for this resource" error, even when using the gcloud command.

Here's a detailed breakdown of what I've tried:

API Enabled: The Cloud Text-to-Speech API is definitely enabled in my project. I've verified this multiple times in the API Library.

Project Association: My Apps Script project is linked to the correct Google Cloud project. The project ID and project number match between Apps Script and the Google Cloud Console.

Service Account: I've created (and recreated) a service account specifically for this purpose. I've tried both a new service account and the original one.

gcloud Command: I'm using the following gcloud command (with the correct project ID and service account email):

Bash

    gcloud projects add-iam-policy-binding [redacted for security] --member="serviceAccount:[redacted for security]" --role="roles/cloud.texttospeech.client"

This command returns the "Role roles/cloud.texttospeech.client is not supported for this resource" error.

IAM (at the project level): I've tried adding the "Cloud Text-to-Speech Client" role to the service account at the project level through the IAM page in the Google Cloud Console. However, the role is not listed in the dropdown (even after searching). I have also tried typing the full role ID (roles/cloud.texttospeech.client) in the role selection field, but that did not work.

Key File: I've downloaded a new JSON key file for the service account after making any changes to permissions and have updated the google_credentials script property in my Apps Script with the content of this new key file.

OAuth Consent Screen: I have configured the OAuth consent screen with the scope. (Although I understand this may not be necessary for service accounts.)

Apps Script Code: I'm using a very simple testTTS() function for testing. The error I get in the Apps Script execution log is:

TTS Error (Fetch): SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
转载请注明原文地址:http://anycun.com/QandA/1744884372a88990.html