Python 3 Google Translation API Script to Build Voice Translation From Microphone & Export to MP3
3K views
Jun 1, 2025
Get the full source code of application here: https://codingshiksha.com/python/python-3-google-translation-api-script-to-build-voice-translation-from-microphone-export-to-mp3/
View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video I will show you a Python
0:04
script which again will be responsible
0:06
for building a voice recognizer Google
0:11
translator translating your text from
0:13
one language to another so let me just
0:15
run this Python script it's using quite
0:17
a number of third party packages of
0:20
Python you can see GTS uh Google
0:23
translate speech recognition everything
0:26
let me first of all initialize this
0:28
application by running it python app.py
0:31
so as soon as you run this you will see
0:33
speak hello to initiate the translation
0:36
hello so now it will actually initiate
0:39
your translation so it will say that
0:41
speak a sentence to translate so I'm
0:44
speaking some kind of
0:46
sentence so you will see now it will
0:49
create this MP3 file
1:00
so let me just
1:04
[Music]
1:08
turn so you can see that guys it
1:10
translated to this language
1:14
if you want your name so in this easy
1:17
way you can translate your text directly
1:20
in the terminal and it will create a MP3
1:22
file in that specific language you can
1:26
uh I have given this script in the
1:28
description of the video so you can
1:30
basically translate to any language here
1:33
this is Hindi here that's why this
1:35
twolet digit code it is translating your
1:37
English text into Hindi let me translate
1:40
this to ES es stands for Spanish here
1:43
you just need to paste the twolet digit
1:47
language code and now if I just run this
1:50
script here so now what it will do again
1:53
you repeat the same process type hello
1:56
to initiate the trans translation and
1:58
you just speak any sort of sentence here
2:00
you will speak speaking a test sentence
2:02
it will be translating this English from
2:05
Spanish
2:08
so it will do the
2:11
translation and then it will create this
2:13
MP3
2:23
file so as you can see guys it's
2:25
successfully translated my English
2:28
sentence to Spanish
2:31
uh automatically then created this MP3
2:33
file and automatically played the file
2:35
as well so all the things are happening
2:37
at the same time here so let me now show
2:39
the Python script here i have given the
2:42
script in the description of the video
2:44
you can go to my blog post and
2:47
directly paste the
2:50
script so now let me just show you how I
2:54
built this so first of all delete
2:57
everything just create a simple app py
3:00
file and then we require the necessary
3:02
packages first of all the speech
3:04
recognition as
3:07
SPR and then we also require this Google
3:10
translate package from translator it's a
3:14
free Google translator API package for
3:18
Python and then we also have this
3:20
package
3:22
gtts from this we import
3:25
this after importing all the packages we
3:28
require we recognize the speech
3:31
recognizer we initialized this it
3:33
contains this recognizer function we
3:37
initialized it after initializing it we
3:39
simply give the permission to your
3:42
microphone and we use this microphone
3:45
method and here we pass your device
3:47
index your microphone index so I simply
3:50
pass my microphone index and uh after
3:54
that we simply require like this we
4:00
specify and just put
4:03
the we will say to the user speak
4:06
anything and uh start by speaking hello
4:10
to initiate the translation
4:14
so after that we
4:16
specify we recognize the text that the
4:19
user will speak and store it inside my
4:24
text and this
4:30
recognizer it contains this function
4:32
here which let me now we need to define
4:35
this function which is recognize speech
4:38
we basically pass the recognizer one and
4:41
the source
4:48
So whatever the microphone it will
4:50
automatically detect your language and
4:52
store it inside this source so we are
4:53
passing this to this function now we
4:55
just need to define this function which
4:57
is
4:59
recognize
5:01
speech it will automatically take these
5:04
two arguments first of all your
5:10
recognizer and then your
5:13
source inside this function inside the
5:16
try catch block we
5:18
specify the recognizer and we simply use
5:22
this function here adjust for
5:27
ambient
5:29
noise so here we are simply reducing the
5:32
noise here which is coming from the
5:35
microphone and then extracting all the
5:38
audio and converting that audio that
5:41
speech to
5:42
audio and returning this
5:49
text so this is all the function right
5:52
here we are getting
5:54
this text
5:57
stored inside this
6:01
variable so after that we get the text
6:04
we translate this text to the native
6:06
language that you
6:09
specify my
6:11
text and hello in my
6:16
text if this is the case here we now
6:20
initialize our translator
6:22
service we initialize it and then we
6:25
specify the from language and the two
6:29
language so here you just need to paste
6:32
the twolet digit code so we are
6:33
translating it from English to Hindi so
6:37
after that we
6:39
again convert this and then conver uh
6:42
create a MP3 file so again we initialize
6:47
this so we again call this if
7:02
get so all the script guys I've given in
7:05
the description of the video essentially
7:07
it is translating it to the native
7:09
language and then it is using this GTS
7:12
package to create a MP3 file to create
7:14
this uh uh convert this text into
7:19
MP3 and
7:21
then starting that MP3 file
7:23
automatically so so this completes your
7:26
script so again if
7:31
you let me just uh again start
7:36
this so all this script is given in the
7:39
description of the video so if you have
7:41
any sort of doubt you can go to that web
7:44
page and directly copy paste the script
7:47
so once you paste it simply go to your
7:49
terminal run this and hello speak hello
7:54
to initiate the translation and then
7:56
speak any sort of sentence through your
7:58
microphone and that sentence will be
8:00
translated to
8:03
the language that you have
8:07
specified so you can see automatically
8:19
So in this easy way guys you can build
8:22
out this voice
8:24
translator plus with Google translate
8:27
automatically built in so in this easy
8:29
way you can build this all the source
8:31
code is given in the description of the
8:33
video uh thank you very much for
8:35
watching this video please hit that like
8:37
button and subscribe the channel and
8:39
also check out my website uh
8:42
freemediatools.com uh which contains uh
8:45
thousands of tools
#Intelligent Personal Assistants
#Programming
#Scripting Languages
#Software
#Voice & Video Chat