Hello everyone. In this article, I will introduce how to use Python and AI to automatically translate English audio files into Japanese and then synthesize them into speech. This technology aims to recreate the recently popular Google NotebookLM "Audio Overview" feature in Japanese.
By the way, I have published output images and screen captures that could not be fully covered in this note on YouTube!
In this note, I will explain in detail the benefits, use cases, code, and step-by-step configuration methods that could not be introduced in detail in the YouTube video.
Image of the final result
First, I will share an image of what the final result will look like. The deliverable will be
this audio file.
The original audio file is here.
To be honest, compared to the smoothness of the original audio, there is still room for improvement, but in terms of content, I think it can be said that a certain level of Japanese localization has been achieved!
Now, let's get straight into the specific details!
The significance of converting English audio to Japanese speech
Why is this technology necessary?For example, Google's NotebookLM "Audio Overview" feature uses two AI hosts to summarize content based on user documents, discuss the relationships between topics, and provide it in WAV format. However, it is currently only available in English.
By recreating this audio in Japanese, the following benefits are created:
Information access that transcends language barriers
Efficient learning and information gathering
Automation of content localization
Promotion of multilingual communication
Using the method introduced throughout this note, you can convert anything into Japanese audio, not just NotebookLM, as long as it is within the volume range acceptable for Text-to-Speech with English audio sources. Specifically, it covers the following content.
Main Use Case 1: Translation and Audio Conversion of Educational ContentYou can listen to excellent overseas lectures and seminars in Japanese:
Japanese localization of lectures from MOOC platforms (Coursera, edX, etc.)
Enjoy TED Talks with Japanese audio
Take university lectures from abroad in Japanese
In global business, you can gather and understand information quickly:
Grasp the content of overseas meetings and conference calls in Japanese in real-time
Listen to English business podcasts in Japanese
Convert overseas market reports into Japanese audio
Remove language barriers for entertainment and information programs:
Watch overseas documentaries with Japanese audio
Convert foreign language news programs into Japanese in real-time
Enjoy overseas radio programs in Japanese
It serves as an effective learning tool for language learners:
Learn by listening to the original language and Japanese translation alternately
Compare your own pronunciation with the synthesized voice
Support for creating listening materials
Time savings: Eliminates the need for manual translation or voice dubbing, allowing for significant time reduction.
Cost reduction: Eliminates the need to hire professional translators or voice actors, reducing the cost of content localization.
Scalability: Since large amounts of content can be processed automatically, efficient information processing is possible.
Real-time capability: Because overseas information can be converted into Japanese in near real-time, quick access to the latest information becomes possible.
Improved learning efficiency: In foreign language learning, you can study while comparing the original language with Japanese, which deepens understanding.
Improved accessibility: By removing language barriers, more people can access information.
Selection of diverse voice qualities: By using multiple voices, richer content creation becomes possible.
Consistency: By using machine translation and speech synthesis, consistency in translation and pronunciation is maintained.
Translation quality: AI-based translation may not always understand context or subtle nuances as well as a human translator.
Naturalness of speech: Synthesized speech may not be able to express emotions or intonation as well as a human voice actor.
Copyright issues: Since copyright issues may arise with the translation and redistribution of content, careful attention is required when using it.
API usage fees: When using Google Cloud APIs, fees are incurred based on usage.
Technical barriers: Technical knowledge such as Python programming and the configuration of various APIs is required.
Processing time: Depending on the length of the audio file, processing may take some time.
Security and Privacy: When processing highly confidential content, there are risks associated with using cloud-based services.
Language and Dialect Limitations: It may not be possible to support specific languages, dialects, or technical terminology.
Now, I have explained the significance of converting English audio sources into Japanese. While the needs mentioned above have certainly existed for some time, I would also like to talk about NotebookLM, which served as the inspiration for this project. A major point is that NotebookLM's Audio Overview has made it much easier to generate podcast-like audio using a user's own information (such as PDFs).
What is NotebookLM?
Features of NotebookLMFirst, let's briefly explain NotebookLM. NotebookLM is a powerful information understanding tool developed by Google. Leveraging the capabilities of Gemini 1.5, it provides expert-level knowledge instantly based on materials uploaded by the user. The following are the main features of NotebookLM:
Source-based responses: Generates answers based on uploaded materials and provides citations and related references.
Privacy-focused: User personal data is never used to train the models.
Multimodal support: It can process not only text documents but also Google Slides, images, web URLs, and more.
Multifunctional: Offers various features such as fact-checking, study guide creation, and briefing document generation.
Audio Overview is one of the new features of NotebookLM. Using this feature, you can generate conversational audio content featuring two AI hosts based on the materials you upload. The AI hosts summarize the content of the materials and provide information in a dialogue format while explaining the connections between topics.
Latest Updates to NotebookLMRecent updates have added the following features:
Conversation customization: Users can now specify the focus and level of expertise for the conversation.
Background playback: You can continue working within NotebookLM while listening to the Audio Overview.
Here are some tips for effectively utilizing NotebookLM:
Upload recent documents to experiment: Try uploading the 10 documents you have worked with recently and ask questions about them.
Use main notebooks and individual notebooks separately: Create a "general knowledge" notebook and separate notebooks for specific projects.
Find connections between multiple documents: Integrate scattered information with NotebookLM and discover the links between them.
Utilize suggested questions: Start with the questions proposed by NotebookLM to expand your ideas.
Change how information is displayed: You can view information in various formats, such as FAQs, briefing documents, timelines, and tables of contents.
Explore creative uses: You can also utilize it in creative fields such as writing novels or scripts, and game development.
Leverage Audio Overview: Convert your uploaded materials into an Audio Overview to gain new perspectives.
Review chat sessions: Summarize your interactions with NotebookLM so you can refer back to them later.
That concludes my brief explanation of NotebookLM. Now, I would like to explain how to create a Japanese audio file using the audio file generated by this NotebookLM.
How to Create a NotebookLM-style Japanese 'Audio Overview' Powered by Python + AI
Implementation OverviewThe general flow for implementing this technology is as follows:
-
Google Colab Setup
Gemini API Setup
Text to Speech API Setup
-
Audio File Processing
Transcription
Translation from English to Japanese
-
Japanese Text Speech Synthesis
Speaker identification and voice assignment
Text-to-speech conversion
Combining and saving the synthesized audio
Gemini API Setup
First, I will explain the basic steps for using the Gemini API (you can also refer to this article for detailed setup screens, etc.).
-
Obtaining a secret key from Google AI Studio:
Access Google AI Studio and create an API key from "Create API key".
No credit card registration is required, and you can get started easily.
Installing necessary libraries: Run the following command in Google Colab.
!pip install -q -U google-generativeai
And, the basic usage of the Gemini API is as follows.
import os
from dotenv import load_dotenv
import google.generativeai as genai
API-KEYの設定
GOOGLE_API_KEY = 'あなたのAPIキー'
genai.configure(api_key=GOOGLE_API_KEY)
gemini_pro = genai.GenerativeModel("gemini-pro")
prompt = "こんにちは"
response = gemini_pro.generate_content(prompt)
print(response.text)With this code, you can generate simple responses using the Gemini Pro model.
How to use Text to Speech
Next, I will explain the setup steps for using the Google Cloud Text-to-Speech API (you can also refer to this article for detailed setup screens, etc.).
-
Creating a GCP project:
Create a new project in the Google Cloud Console.
Enable the Text-to-Speech API.
-
Creating and authenticating a service account:
Create a service account and download the JSON key.
Using the Text To Speech API while loading the account key and setting environment variables in Google Colab
!pip install google-cloud-texttospeech
import os
from google.colab import drive
from google.cloud import texttospeech
Google Driveをマウント
drive.mount('/content/drive')
Google Cloudの認証情報を設定
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/content/drive/MyDrive/GoogleCloud/your-credentials-file.json" # サービスアカウントキーを保存した任意のファイルを指定してください。
client = texttospeech.TextToSpeechClient()
synthesis_input = texttospeech.SynthesisInput(text="おはようございます!今日も元気にがんばりましょう")
voice = texttospeech.VoiceSelectionParams(
language_code="ja-JP", ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL
)
audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.MP3
)
response = client.synthesize_speech(
input=synthesis_input, voice=voice, audio_config=audio_config
)
with open("/content/drive/MyDrive/audioOutput/output.mp3", "wb") as out:
out.write(response.audio_content)
With this code, you can generate audio files from text.
With this, you are now able to use the Gemini API and the Text To Speech API. Using these APIs, we will synthesize the audio for NotebookLM, which is our goal this time, into a Japanese audio file.
Below, I will first show the entire code, and then provide an explanation. If you can replace the settings such as the authentication file, I think it is possible to just copy and paste it to get it running, skipping the fine details.