![]() Language_code, voice_name = language_dictģ. # Set the language and voice for Google TTS based on the detected language # Define a dictionary to map the detected language to language code and voice nam You can find the voice profile from here. ![]() I selected four languages here, French, Chinese, Japanese and English. So I used a Python library called langdetect.ġ. I was not able to do this natively with OpenAI because I couldn't find a language attribute from neither the Whisper nor ChatGPT response. Google TTS creates the audio in the correct language Detect the language from ChatGPT API response. Pass the audio to Whisper API to transcribe. How about we uplift the bot again so it can detect your language and respond correspondingly? That's pretty cool huh!įirst, let's remind ourselves how the bot works. Print('Audio content written to file "output.mp3"')Īuto detect and respond in different languages 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Ĭlient = texttospeech.TextToSpeechClient(credentials=credentials) ![]() 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.
0 Comments
Leave a Reply. |