Google speech api languages1/11/2024 ![]() Then we use uuid library to generate the audio file called filename, which is returned to Gradio to play back. The above code passes the ChatGPT API response system_message to the Google TTS module, selected a voice and generated the speech as a mp3 file.ģ. Input=synthesis_input, voice=voice, audio_config=audio_config Language_code="en-GB", name="en-GB-Neural2-A"Īudio_encoding=3 Voice = texttospeech.VoiceSelectionParams( Synthesis_input = texttospeech.SynthesisInput(text=system_message) # generate speech from system_message using Google Cloud Text-to-Speech API from google.oauth2 import service_accountĬredentials = service_service_account_file("/path/to/Google/JSON/Credential") Next we will remove pyttsx3 code and replace with the Google TTS code. engine = pyttsx3.init(ĮtProperty("voice", "english-us")Įngine.save_to_file(system_message, "response.mp3")Ģ. The ChatGPT API response is passed on to system_message, which gets converted to a mp3 file and returned to Gradio. Just to refresh what we did in the last episode. Now, let's have a look at the existing code for pyttsx3 section where we convert the text to audio for Gradio to play back. Before the code can successfully run, I need to enable Text-to-Speech API.ġ. Pip install -upgrade google-cloud-texttospeechġ1. Make sure you have the latest version of the package installed by including the -upgrade flag. Btw, you need to install the google-cloud-texttospeech package in your Python environment. from google.cloud import texttospeechĬlient = texttospeech.TextToSpeechClient(credentials=credentials)ġ0. Then, you can pass the credentials to the TextToSpeechClient constructor. from google.oauth2 import service_accountĬredentials = service_service_account_file('/path/to/key.json')ĩ. Replace the path to locate the JSON file. Create a new key and select JSON as the format. Click the three dots and choose Manage keys.ħ. Back at CRENDENTIAL VIEW, select Manage service accounts.Ħ. Assign the Cloud Speech Administrator role, select CONTINUE.ĥ. Provide service account details, you can call it anything. Log on to Google Cloud portal, select Credentials - CREATE CREDENTIALS - Service account.Ģ. ![]() Create Google Service Account and download JSON keyġ.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |