作者|Dipesh Pal 编译|Flin 来源|analyticsvidhya

介绍

虚拟助手(也称为AI助手或数字助手)是一款应用程序,可以理解自然语言的语音命令并为用户完成任务。

我们应该都知道什么是虚拟助手。打开手机并说“ Ok Google”或“ Hey Siri”。Google助手,Siri,Alexa都是虚拟助手的示例。

演示和编码YouTube视频:

  • https://youtu.be/LliTjuxDw_o

内容

  1. 我们要做什么

  2. 代码说明

  3. 完整的代码

  4. GitHub储存库

  5. 你如何贡献

  6. 参考文献

1.我们要做什么

我们的虚拟助手将能够执行以下操作

天气预报,启动游戏,启动Windows应用程序,打开网站,告诉你几乎你所要求的一切,告诉你日期和时间,问候,新闻等。

你可以与笔记本电脑的麦克风/控制台进行交互。助手生成的响应将显示在控制台上,或者通过扬声器直接说出来。

未来的可能:自拍,与人聊天更多,等等。

2. 代码说明

让我们一起来创建自己的虚拟助手。

  • 所有代码都可以在我的GitHub上找到。
  • 我的频道上还提供了演示YouTube视频和代码YouTube视频。
  • 所需的链接和软件包如下所述。
  • 如果你愿意分享,我将不胜感激。

2.1 所需的软件包和库

pip install JarvisAI

这是我创建的最新虚拟助手模块。它提供任何虚拟助手的基本功能。前提条件是Python版本 > 3.6。

用法和功能

安装库后,你可以导入模块

import JarvisAI
obj = JarvisAI.JarvisAssistant()
response = obj.mic_input()
print(response)

功能通过方法名称清除。例如,你可以检查代码。

  1. mic_input
  2. text2speech
  3. shutdown
  4. website_opener
  5. send_mail
  6. tell_me_date
  7. tell_me_time
  8. launch_any_app
  9. weather
  10. news
  11. tell_me

在这里关于它的信息

  • https://pypi.org/project/JarvisAI/

你也可以在这里为这个存储库做贡献。

  • https://github.com/Dipeshpal/Jarvis_AI

2.2 编码

导包

import JarvisAI
import re
import pprint
import random

根据文档创建 JarvisAI的对象

obj = JarvisAI.JarvisAssistant()

我们已经创建了这个“t2s(text)”函数。这会将任何文本转换为语音。我们将使用(调用)此函数的整个程序从文本产生语音。

def t2s(text):obj.text2speech(text)

我们希望不断听取用户的输入,因此此“ mic_input() ”将尝试从计算机的麦克风中连续获取音频。它将处理音频并在“ res”变量中返回文本。我们可以使用此“ res”变量根据用户输入执行某些操作。

while True:res = obj.mic_input()

天气预报:我们使用正则表达式来匹配用户输入中的查询。如果在用户输入“ res”中找到“天气”或“温度”,则我们要进行天气预报。无需从头开始编写东西,只需调用“ obj.weather(city = city)”即可。

你只需要从用户输入中获取城市并将其传递给天气功能即可。它会告诉你你所在城市的天气预报。

我们可以将此返回的“ weather_res”传递到“ t2s(weather_res)”,以从“ weather_res”字符串中产生语音。

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)

新闻:与上述类似,匹配用户输入“ res”中的“新闻”一词。如果匹配,则调用“ obj.news”。

它将返回15条新闻作为字符串列表。因此,我们可以将新闻作为“ news_res [0]”来获取,并将其传递给“ t2s(news_res [0])”。

while True:res = obj.mic_input()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])

讲述几乎所有内容:它将从维基百科中获取前500个字符,并将它们作为字符串返回。你可以使用'obj.tell_me(topic)'。

你需要将“主题”传递给“ tell_me(topic = topic)”。主题是你想知道的关键字。

while True:res = obj.mic_input()if re.search('tell me about', res):topic = res.split(' ')[-1]wiki_res = obj.tell_me(topic)print(wiki_res)t2s(wiki_res)

日期和时间:它将告诉你系统的当前日期和时间。

while True:res = obj.mic_input()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)

打开任何网站:此'obj.website_opener(domain)'将为你打开任何网站。你只需要从用户输入中获取domain,然后传递给'obj.website_opener(domain)'。它将在你的默认浏览器中打开网站。

while True:res = obj.mic_input()if re.search('open', res):domain = res.split(' ')[-1]open_result = obj.website_opener(domain)print(open_result)

启动任何应用程序游戏等

这有点棘手,在“ obj.launch_any_app(path_of_app = path)”中,你需要传递“ .exe”文件路径的函数。

因此,我们创建了“ dict_app”字典,其中以“应用名称”作为键,以“路径”作为值。我们可以使用此“ dict_app”进行查找。如果字典中存在用户输入的应用程序,那么我们将通过获取路径来打开它。

以下示例仅适用于Chrome和Epic Games。

while True:res = obj.mic_input()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)

问候和聊天,你现在可以像这样创建问候和聊天。

我正在 https://pypi.org/project/JarvisAI/ 上使用Tensorflow添加聊天功能。你可以为使其更好而做出贡献。

while True:res = obj.mic_input()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")

你能做什么?”:在这里,我们只是使用“ obj.t2s()”来发表讲话。如果你了解python,则可以轻松理解以下代码

while True:res = obj.mic_input()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)

3.完整的代码

import JarvisAI
import re
import pprint
import randomobj = 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)

4. Github仓库

你可以随意使用我的代码。如果你喜欢我的作品,请为其点亮star;如果你喜欢,请在YouTube上订阅。

只需克隆存储库

  • https://github.com/Dipeshpal/Jarvis-Assisant.git

然后运行pip install -r requirements.txt

它将自动安装所有内容。

5. 如何贡献

只需打开此GitHub存储库,阅读该书,你将了解你如何做出贡献。

  • https://github.com/Dipeshpal/Jarvis_AI

你的贡献将反映在这个项目上。

  • https://pypi.org/project/JarvisAI/

6. 参考

GitHub存储库和代码

  • https://github.com/Dipeshpal/Jarvis-Assisant.git

贡献的GitHub Pypi存储库

  • https://github.com/Dipeshpal/Jarvis_AI

JarvisAI库

  • https://pypi.org/project/JarvisAI/

YouTube频道

  • https://www.youtube.com/DIPESHPAL17

演示和代码(YouTube)

  • https://youtu.be/LliTjuxDw_o

原文链接:https://www.analyticsvidhya.com/blog/2020/09/ai-virtual-assistant-using-python/

欢迎关注磐创AI博客站: http://panchuang.net/

sklearn机器学习中文官方文档: http://sklearn123.com/

欢迎关注磐创博客资源汇总站: http://docs.panchuang.net/

如何使用Python创建AI虚拟助手相关推荐

  1. Siri 创始人: AI 虚拟助手未来5年内将彻底改变医疗行业

    图片来源:ktsdesign / Shutterstock 雷锋网消息,今年夏天, KPCB 合伙人玛丽·梅克尔(Mary Meeker)在<2017年互联网趋势报告>中指出,医疗保健领域 ...

  2. 使用Python+JarvisAI实现AI虚拟助手

    介绍 虚拟助手(也称为AI助手或数字助手)是一款可以理解语音命令的自然语言并为用户完成特定任务的应用程序. 我们应该都知道什么是虚拟助手,比如打开手机并说" Ok Google"或 ...

  3. python的ai写作_使用Python创建AI比你想象的轻松

    可能对AI领域,主要开发阶段,成就,结果和产品使用感兴趣.有数百个免费源和教程描述使用Python的AI.但是,没有必要浪费你的时间看他们.这里是一个详细的指南,你需要知道在使用Python构建人工智 ...

  4. python制作ai小说网_【案例分享】使用Python创建AI比你想象的轻松

    您可能对AI领域,主要开发阶段,成就,结果和产品使用感兴趣.有数百个免费源和教程描述使用Python的AI.但是,没有必要浪费你的时间看他们.这里是一个详细的指南,你需要知道在使用Python构建人工 ...

  5. 使用Python创建AI比你想象的轻松

    您可能对AI领域,主要开发阶段,成就,结果和产品使用感兴趣.有数百个免费源和教程描述使用Python的AI.但是,没有必要浪费你的时间看他们.这里是一个详细的指南,你需要知道在使用Python构建人工 ...

  6. Python控制AI虚拟主播说话聊天源码分享

    Python是非常简单可用的脚本语言,本次我们将介绍如何实用Python控制一个AI虚拟主播说话聊天.通过分析目前市场上可用的虚拟主播软件,发现Motionface是一个简单可用的虚拟主播软件,它提供 ...

  7. 相芯科技蔡锐涛:AI虚拟形象——没有最完美,只有更完美

    在LiveVideoStackCon2019深圳音视频技术大会前夕,我们邀请到了相芯科技资深图形引擎开发经理蔡锐涛老师接受采访,从个人成长聊到智能图形技术方面的创新与应用,再到相芯科技在虚拟形象上的优 ...

  8. python国际象棋ai程序_使用Python创建属于你的国际象棋AI

    使用Python创建属于你的国际象棋AI Python3 最后更新 2020-10-23 16:23 阅读 120 最后更新 2020-10-23 16:23 阅读 120 Python3 ##Fly ...

  9. 重磅!Amazon发布个人免费的AI编程助手:CodeWhisperer !

    来源:https://juejin.cn/post/7223746457941508157 现已正式推出实时 AI 编程助手 Amazon CodeWhisperer,包括 CodeWhisperer ...

最新文章

  1. 顺序队列之C++实现
  2. 《构建之法》阅读笔记07
  3. Apache通过配置.htaccess文件禁止访问.git、.svn等目录
  4. linux下file命令使用技巧
  5. C语言链表返回具有的回文序列的算法(附完整源码)
  6. 整数反转—leetcode7
  7. 物联网避坑 3 大指南!
  8. 网抑云体验室PHP网站源码
  9. Ubuntu下Hadoop的安装和配置
  10. 码农跳槽指南:如何在新公司建立自己的“支配地位”?
  11. c语言中根号绝对值,根号的绝对值怎么算?
  12. 4000亿农夫山泉的生意经
  13. python3实现base64编码
  14. MSN群每周讨论之快速估算和管理
  15. Android 系统(213)---如何内置多张静态壁纸(图片)到系统中
  16. xiuno开发文档_$ip-XiunoPHP 4.0 开发手册
  17. 北部湾及涠洲岛海域潮汐和海平面特征
  18. 神秘的程序员头像包(附口罩版)第一发
  19. 实现NRF52832蓝牙DFU无线升级
  20. 磁盘盘符隐藏并访问隐藏磁盘的文件数据

热门文章

  1. 使用计算机传真,如何用电脑发网络传真?在电脑里怎么发传真?
  2. 关于asp输出json对象的方法及实例
  3. SimpleDateFormat的使用
  4. 【正点原子MP157连载】第十二章 按键输入实验-摘自【正点原子】STM32MP1 M4裸机CubeIDE开发指南
  5. 这些清北高考状元的“学习秘籍”还不快快收藏?
  6. 动态路由原理(RIP协议+实验)
  7. 盛大业绩又在下滑,难道盛极一时的盛大将从此没落?
  8. 图片转换工具类 base64、Uri转String
  9. cmath中的log函数
  10. 我真的没读野鸡大学!是他们不好好起名字!