Skip to content

Commit

Permalink
POC for working on cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshitRuwali committed Dec 1, 2021
1 parent ccdc719 commit fe70bf1
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 10 deletions.
16 changes: 10 additions & 6 deletions cli/voice_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ def clear(): return os.system('clear')
clear()


def main():
func(listen.listen())
# def main():
# func(listen.listen())


def func(command):
if "hello" in command:
current_time = int(strftime('%H'))
if current_time < 12:
bot.bot("Hello, Good morning, this is your voice assistant.")
# bot.bot("Hello, Good morning, this is your voice assistant.")
return ("Hello, Good morning, this is your voice assistant.")
elif 12 <= current_time < 16:
bot.bot("Hello, Good afternoon, this is your voice assistant.")
# bot.bot("Hello, Good afternoon, this is your voice assistant.")
return ("Hello, Good afternoon, this is your voice assistant.")
else:
bot.bot("Hello, Good evening, this is your voice assistant.")
# bot.bot("Hello, Good evening, this is your voice assistant.")
return ("Hello, Good evening, this is your voice assistant.")

elif "who made you" in command:
bot.bot("I was developed by The Team SkyDocs.")
Expand Down Expand Up @@ -134,4 +137,5 @@ def func(command):
sys.exit()

else:
bot.bot("I am sorry, I am unable to process your request.")
# bot.bot("I am sorry, I am unable to process your request.")
return command
4 changes: 0 additions & 4 deletions voice_assistant_cli.py

This file was deleted.

32 changes: 32 additions & 0 deletions voice_assistant_cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import base64
from flask import Flask, jsonify, request
from flask_cors import CORS

from cli import voice_assistant as vs


app = Flask("Personalised Voice Assistant")

CORS(app)

@app.route('/', methods=['POST'])

def predict():
data_ret = request.get_json()
command = data_ret["command"]
command = base64.b64decode(command)
command = str(command, "utf-8")

# call the main function
response = vs.func(command)

response = {
"response": response
}
response = jsonify(response)

return response


if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
53 changes: 53 additions & 0 deletions voice_assistant_front_end.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import base64
import requests
import speech_recognition as sr
import pyttsx3
import json


def listen():
mic = sr.Microphone()
r = sr.Recognizer()

with mic as source:
audio = r.listen(source, phrase_time_limit = 5)
try:
command = r.recognize_google(audio).lower()
except sr.UnknownValueError:
listen()
return command

# command = listen()

command = "hello"
# command = command.encode("utf-8")

command = base64.b64encode(command.encode("utf-8"))
command = str(command, "utf-8")

# command = command.decode("utf-8")

url = "http://127.0.0.1:8080"

response = requests.post(url,json = {"command":command})

response = response.text.strip()
print(response)

response = json.loads(response)

print(response['response'])

voice_id = "english-north"

engine = pyttsx3.init()
rate = engine.getProperty('rate')
engine.setProperty('rate', 190)
volume = engine.getProperty('volume')
engine.setProperty('volume', 1.0)
sound = engine.getProperty('voices')
engine.setProperty('voice', voice_id)

for i in str(response).splitlines():
engine.say(response)
engine.runAndWait()

0 comments on commit fe70bf1

Please sign in to comment.