Goal

MLE will be added to Oracle APEX upcoming releases. It contains the support of brilliant language Python. I will be ready to integrate my code once its ready!

 

Given:

- macOS High Sierra 10.13.6

- python3 Version

$ python3 --version
Python 3.7.1

 

- brew version

$ brew --version
Homebrew 1.8.6

 

Prerequisites

brew

brew install mpg321
brew install portaudio

 

pip3

pip3 install amp
pip3 install pyaudio
pip3 install pyspeech
pip3 install speechrecognition
pip3 install googletrans

 

ArToEnVoiceTranslator.py

#!/usr/bin/env python3

# Requires PyAudio and PySpeech.

import speech_recognition as sr

from time import ctime

import googletrans as gt

import time

import os

from gtts import gTTS

def speak(audioString,mylang):

print(audioString)

  tts = gTTS(text=audioString, lang=mylang)

  tts.save("audio.mp3")

  os.system("mpg321 audio.mp3")

def recordAudio():

# Record Audio

  r = sr.Recognizer()

with sr.Microphone() as source:

print()

  audio = r.listen(source)

# Speech recognition using Google Speech Recognition

  data = ""

try:

# Uses the default API key

# To use another API key: `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`

  data = r.recognize_google(audio ,language="ar-SA")

print("You said: " + data)

except sr.UnknownValueError:

print("***")

except sr.RequestError as e:

print("Could not request results from Google Speech Recognition service; {0}".format(e))

return data


def translateToEnglish(text):

if text != "":

  mygt = gt.Translator()

  translation = mygt.translate(text,dest='en')

  speak(translation.text,'en')

# initialization

time.sleep(1)

speak('السلام عليكم هذا مترجم للكلام من اللغة العربية إلى اللغة الانجليزية، رجاء تكلم بالكلمة العربية واصبر ليتم ترجمتها لك بالانجليزية','ar')

while 1:

  data = recordAudio()

  translateToEnglish(data)

 

 

Regards

Mahmoud