-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccdc719
commit fe70bf1
Showing
4 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |