使用Python+JarvisAI实现AI虚拟助手
虚拟助手(也称为AI助手或数字助手)是一款可以理解语音命令的自然语言并为用户完成特定任务的应用程序。
pip install JarvisAI
Python版本 > 3.6
只需克隆存储库
-
https://github.com/Dipeshpal/Jarvis-Assisant.git
然后运行pip install -r requirements.txt
它将自动安装所有内容。
完整代码:
import JarvisAI
import re
import pprint
import random
obj = JarvisAI.JarvisAssistant()
def t2s(text):
obj.text2speech(text)
while True:
res = obj.mic_input()
if re.search('weather|temperature', res):
city = res.split(' ')[-1]
weather_res = obj.weather(city=city)
print(weather_res)
t2s(weather_res)
if re.search('news', res):
news_res = obj.news()
pprint.pprint(news_res)
t2s(f"I have found {len(news_res)} news. You can read it. Let me tell you first 2 of them")
t2s(news_res[0])
t2s(news_res[1])
if re.search('tell me about', res):
topic = res.split(' ')[-1]
wiki_res = obj.tell_me(topic)
print(wiki_res)
t2s(wiki_res)
if re.search('date', res):
date = obj.tell_me_date()
print(date)
print(t2s(date))
if re.search('time', res):
time = obj.tell_me_time()
print(time)
t2s(time)
if re.search('open', res):
domain = res.split(' ')[-1]
open_result = obj.website_opener(domain)
print(open_result)
if re.search('launch', res):
dict_app = {
'chrome': 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',
'epic games': 'C:\Program Files (x86)\Epic Games\Launcher\Portal\Binaries\Win32\EpicGamesLauncher.exe'
}
app = res.split(' ', 1)[1]
path = dict_app.get(app)
if path is None:
t2s('Application path not found')
print('Application path not found')
else:
t2s('Launching: ' + app)
obj.launch_any_app(path_of_app=path)
if re.search('hello', res):
print('Hi')
t2s('Hi')
if re.search('how are you', res):
li = ['good', 'fine', 'great']
response = random.choice(li)
print(f"I am {response}")
t2s(f"I am {response}")
if re.search('your name|who are you', res):
print("My name is Jarvis, I am your personal assistant")
t2s("My name is Jarvis, I am your personal assistant")
if re.search('what can you do', res):
li_commands = {
"open websites": "Example: 'open youtube.com",
"time": "Example: 'what time it is?'",
"date": "Example: 'what date it is?'",
"launch applications": "Example: 'launch chrome'",
"tell me": "Example: 'tell me about India'",
"weather": "Example: 'what weather/temperature in Mumbai?'",
"news": "Example: 'news for today' ",
}
ans = """I can do lots of things, for example you can ask me time, date, weather in your city,
I can open websites for you, launch application and more. See the list of commands-"""
print(ans)
pprint.pprint(li_commands)
t2s(ans)
运行视频:
Create your AI Virtual Assistant using Python in 50 lines
详细内容点击:公众号深度学习与计算机视觉