uh hello guys welcome to this video so
in this video I will show you a Python
script which again will be responsible
for building a voice recognizer Google
translator translating your text from
one language to another so let me just
run this Python script it's using quite
a number of third party packages of
Python you can see GTS uh Google
translate speech recognition everything
let me first of all initialize this
application by running it python app.py
so as soon as you run this you will see
speak hello to initiate the translation
hello so now it will actually initiate
your translation so it will say that
speak a sentence to translate so I'm
speaking some kind of
sentence so you will see now it will
create this MP3 file
so let me just
[Music]
turn so you can see that guys it
translated to this language
if you want your name so in this easy
way you can translate your text directly
in the terminal and it will create a MP3
file in that specific language you can
uh I have given this script in the
description of the video so you can
basically translate to any language here
this is Hindi here that's why this
twolet digit code it is translating your
English text into Hindi let me translate
this to ES es stands for Spanish here
you just need to paste the twolet digit
language code and now if I just run this
script here so now what it will do again
you repeat the same process type hello
to initiate the trans translation and
you just speak any sort of sentence here
you will speak speaking a test sentence
it will be translating this English from
Spanish
so it will do the
translation and then it will create this
MP3
file so as you can see guys it's
successfully translated my English
sentence to Spanish
uh automatically then created this MP3
file and automatically played the file
as well so all the things are happening
at the same time here so let me now show
the Python script here i have given the
script in the description of the video
you can go to my blog post and
directly paste the
script so now let me just show you how I
built this so first of all delete
everything just create a simple app py
file and then we require the necessary
packages first of all the speech
recognition as
SPR and then we also require this Google
translate package from translator it's a
free Google translator API package for
Python and then we also have this
package
gtts from this we import
this after importing all the packages we
require we recognize the speech
recognizer we initialized this it
contains this recognizer function we
initialized it after initializing it we
simply give the permission to your
microphone and we use this microphone
method and here we pass your device
index your microphone index so I simply
pass my microphone index and uh after
that we simply require like this we
specify and just put
the we will say to the user speak
anything and uh start by speaking hello
to initiate the translation
so after that we
specify we recognize the text that the
user will speak and store it inside my
text and this
recognizer it contains this function
here which let me now we need to define
this function which is recognize speech
we basically pass the recognizer one and
the source
So whatever the microphone it will
automatically detect your language and
store it inside this source so we are
passing this to this function now we
just need to define this function which
is
recognize
speech it will automatically take these
two arguments first of all your
recognizer and then your
source inside this function inside the
try catch block we
specify the recognizer and we simply use
this function here adjust for
ambient
noise so here we are simply reducing the
noise here which is coming from the
microphone and then extracting all the
audio and converting that audio that
speech to
audio and returning this
text so this is all the function right
here we are getting
this text
stored inside this
variable so after that we get the text
we translate this text to the native
language that you
specify my
text and hello in my
text if this is the case here we now
initialize our translator
service we initialize it and then we
specify the from language and the two
language so here you just need to paste
the twolet digit code so we are
translating it from English to Hindi so
after that we
again convert this and then conver uh
create a MP3 file so again we initialize
this so we again call this if
get so all the script guys I've given in
the description of the video essentially
it is translating it to the native
language and then it is using this GTS
package to create a MP3 file to create
this uh uh convert this text into
MP3 and
then starting that MP3 file
automatically so so this completes your
script so again if
you let me just uh again start
this so all this script is given in the
description of the video so if you have
any sort of doubt you can go to that web
page and directly copy paste the script
so once you paste it simply go to your
terminal run this and hello speak hello
to initiate the translation and then
speak any sort of sentence through your
microphone and that sentence will be
translated to
the language that you have
specified so you can see automatically
So in this easy way guys you can build
out this voice
translator plus with Google translate
automatically built in so in this easy
way you can build this all the source
code is given in the description of the
video uh thank you very much for
watching this video please hit that like
button and subscribe the channel and
also check out my website uh
freemediatools.com uh which contains uh
thousands of tools