Esempio n. 1
0
def main():
    assistant = a.Assistant()
    assistant.load_voice_properties()
    assistant.load_misc_properties()
    assistant.assist()
    assistant.save_voice_properties()
    assistant.save_misc_properties()
Esempio n. 2
0
def main():
    voiceAssistant = assistant.Assistant()
    if platform.system() != "Linux":
        voiceAssistant.say("Error. It is only for Linux")
        sys.exit()
    master = Tk()
    window.Window(master, voiceAssistant)
    master.mainloop()
 def test_assistant(self):
     with patch('os.walk') as mockwalk:
         mockwalk.return_value = [
             ('/foo', ('bar', ), ('baz', )),
         ]
         config.Config = Mock()
         config.Config.get = Mock(return_value=1234)
         bot = assistant.Assistant()
         self.assertEqual(bot.dir,
                          os.path.dirname(os.path.realpath(__file__)))
         self.assertEqual(
             bot.files,
             os.path.dirname(os.path.realpath(__file__)) + '/files')
         self.assertNotEqual(bot.logging, None)
         self.assertNotEqual(bot.config, None)
         self.assertNotEqual(bot.behaviours, None)
    def build_assistant(self):
        Database = Mock()

        # Do not load any behaviours so we are testing those methods separately
        with patch('os.walk') as mockwalk:
            mockwalk.return_value = [
                ('/foo', ('bar', ), ('baz', )),
            ]
            bot = assistant.Assistant()
            bot.responder = Mock()
            bot.responder.get_text = Mock()
            bot.responder.get_text.side_effect = self.mock_get_text
            bot.responder.sendMessage = Mock()
            bot.admin = '1'
            bot.config = Mock()
            bot.config.get = Mock(return_value='1,2')
            bot.config.get_or_request = Mock(return_value='1,2')
            logging = Mock()
            logging.info = Mock()
        return bot
Esempio n. 5
0
# Making virtual assistant which uses voice input to perform specific tasks.


def Listen():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print('Say something...')
        r.pause_threshold = 1
        r.adjust_for_ambient_noise(source, duration=1)
        audio = r.listen(source)
        try:
            command = r.recognize_google(audio).lower()
            print("you said: " + command)
        except sr.UnknownValueError:
            command = Listen()
        return command


while True:
    command = Listen()
    lisa = assistant.Assistant()
    if "open subreddit" in command:
        lisa.subReddit(command)
    elif "open" in command:
        lisa.openWebsite(command)

    elif "stop listening" in command:
        s = 'okay bye bye!'
        print(s)
        break
import apiai
import json
import assistant
import keys
import requests

app = apiai.ApiAI(keys.apiaiKey) # Initialize Dialogflow api (ApiAi is the old name of the service)
Assistant = assistant.Assistant(assistant.voices["female"]) # Initialize our assistant


def translate(word, lang="en"): # This function probably shoud be in assistant class, but I didn't transfered this for now. Args: Text to translete, destination language code
    response = requests.post("https://translate.yandex.net/api/v1.5/tr.json/translate",
                             {"key": keys.translatorKey, "text": word, "lang": lang}) # Requesting json from Yandex Translator
    return json.loads(response.content.decode("utf-8")) # Return response


def get_response(text): # Get response from Dialogflow. Takes text for request.
    request = app.text_request() # Init the text request
    request.lang = 'ru' # Lang of request
    request.session_id = "oosdif87g1" # Session ID should be different in different devices.
    request.query = text # Our request
    response = json.loads(request.getresponse().read().decode('utf-8')) # Reading response
    try:
        return response['result']['fulfillment']['speech'] # Returns just text!
    except Exception:
        return "Произошла ошибка, попробуйте позднее." # If we haven't got response, return sorry message. "An error has occured, try again later."


while True: # Infinite loop for texting
    speech = input("Введите запрос >>  ") # "Enter your request >> "
    response = get_response(speech) # Getting response with "speech" variable request
Esempio n. 7
0
"""
start script
"""

import assistant

# run assistant instance
instance = assistant.Assistant()
instance.run()