声控助手
by Mithi
由Mithi
For almost a year, I worked at an advertising agency as a creative technologist. Based on the insight that innovation drives new businesses and that technology can be creatively applied to brand campaigns, there are a few interesting things I do at my job. I introduce new technologies, do feasibility checks of tech ideas by non-tech creatives, and prototype stuff, among other things.
我在一家广告公司工作了近一年,担任创意技术员 。 基于创新驱动新业务并且技术可以创造性地应用于品牌推广的见解,我在工作中做了一些有趣的事情。 我介绍新技术,对非技术创意人员对技术创意进行可行性检查,并制作原型产品等。
Perhaps one of the most exciting things I did at my job was working with robots! I oversaw the creation of and programmed a 45-inch tall robot for a little more than two months.
也许我在工作中所做的最令人兴奋的事情之一就是与机器人一起工作! 我监督了一个45英寸高的机器人的创建并为其编程了两个多月的时间。
Meet Robbie — also known as HelloBot — an experiment in how humans and technology interact by getting people to connect with a robot the same way people connect with other people. The idea behind Robbie is that technology, such as a robot, can reinforce your brand with each delightful interaction.
认识罗比(Robbie),也称为HelloBot ,这是一种通过使人们以与人与人联系相同的方式与机器人联系来进行人与技术交互的实验。 Robbie的想法是,诸如机器人之类的技术可以通过每次愉快的互动来增强您的品牌。
It’s easier now more than ever to build a sophisticated robot with off-the-shelf parts.
现在,构建具有现成零件的复杂机器人比以往任何时候都更加容易。
This is all thanks to the open-source hardware (OSHW) community. Building a robot is possible because we are standing on the generous shoulders of giants.
这一切都要归功于开源硬件(OSHW)社区。 建立机器人是可能的,因为我们站在巨人的慷慨肩膀上。
All of the electronics used to build Robbie can be bought from DFRobot, Adafruit, and Hobby King. All of them are open-source — the schematics, bill of materials, and PCB board design are free for anyone to download, replicate, or modify.
可以从DFRobot , Adafruit和Hobby King购买用于构建Robbie的所有电子产品。 所有这些都是开放源代码的-原理图,物料清单和PCB板设计免费供任何人下载,复制或修改。
Each component is not a black box where you have to rely on a small customer support team to troubleshoot your issues. When something goes wrong, you have a whole community to help you.
每个组件都不是一个黑盒子,您必须依靠一个小的客户支持团队来解决问题。 当出现问题时,您会得到整个社区的帮助。
Also, because plenty of information is freely given to you, you gain a deeper understanding of how things work.
另外,由于免费提供了大量信息,因此您对事物的工作方式有了更深入的了解。
The brain of our robot is a Raspberry Pi 3, a credit-card sized WiFi-enabled computer. It is connected to a variety of peripherals so the robot can get input and output from the outside world.
我们机器人的大脑是Raspberry Pi 3 ,这是一种信用卡大小的,支持WiFi的计算机。 它连接到各种外围设备,因此机器人可以从外界获得输入和输出。
Some of the inputs are: a microphone so that the robot can hear your words, an 8-megapixel camera so that the robot can see you, and a passive infrared (PIR) sensor which activates when the “average radiation level changes.” This is useful in detecting if human beings move in or out of the robot’s territory.
其中一些输入是:麦克风(使机器人可以听到您的话),8百万像素的摄像头(使机器人可以看到您)以及无源红外(PIR)传感器,当“平均辐射水平发生变化”时,该传感器将激活。 这在检测人类是进入还是离开机器人的区域时非常有用。
Some of the outputs are the 7-inch display where the robot shows its expressions, and audio speakers so you can hear what it’s saying. The Raspberry Pi 3 is connected to WiFi and uses Google’s speech recognition library . It uses an open computer vision (OpenCV) library to recognize faces.
一些输出是7英寸显示屏,机器人在其中显示表情,音频扬声器则使您可以听到它的意思。 Raspberry Pi 3连接到WiFi,并使用Google的语音识别库 。 它使用开放式计算机视觉( OpenCV )库来识别人脸。
The Raspberry Pi 3 communicates with an Arduino Mega microcontroller to delegate low level tasks that the Pi is not good at. The Arduino Mega controls two motor drivers (it has four wheels that you can control independently) so that the robot can move left, right, forward and backward.
Raspberry Pi 3与Arduino Mega微控制器通信以委派Pi不能擅长的低级任务。 Arduino Mega控制两个电机驱动器(它具有四个可以独立控制的轮子),因此机器人可以向左,向右,向前和向后移动。
It also has two servo motors (special motors that can be steered by angle because of built-in feedback circuitry) to move its arms.
它还有两个伺服电机(由于内置反馈电路,可以通过角度操纵的特殊电机)来移动其手臂。
There are also lower level peripherals connected to the Arduino such as colorful RGB-addressable chainable LEDs “Neopixels” to indicate status, and three infrared distance sensors to avoid obstacles.
Arduino还连接了较低级别的外围设备,例如彩色RGB可寻址的可链接LED“ Neopixels ”以指示状态,以及三个红外距离传感器以避免障碍物。
The whole robot (including the motors) is powered by 14.8v 4500 mAh lithium polymer batteries. DC-DC converters regulate the power to bring it down to a lower voltage required to power the Raspberry Pi and Arduino safely.
整个机器人(包括电动机)由14.8v 4500 mAh锂聚合物电池供电。 DC-DC转换器调节电源以将其降低到安全地为Raspberry Pi和Arduino供电所需的较低电压。
We wouldn’t have been able to design, much less understand, any of this if it weren’t for the generous tutorials made by the open-source hardware community — particularly by Adafruit Industries, pioneered by Limor “Lady Ada” Fried.
如果不是开放源代码硬件社区特别是由Limor“ Lady Ada” Fried率先开发的Adafruit Industries所提供的大量教程,我们就无法设计,更不用说了解了。
Here are some of the things I learned throughout this process.
这是我在整个过程中学到的一些东西。
Trying to design “clean” code is very important when you’re trying to build a robot that you’ll love not only to interact with but also build upon.
当您尝试构建不仅要与之交互而且也希望以此为基础的机器人时,尝试设计“干净”的代码非常重要。
I’ve learned to be thoughtful when writing code for this robot, as inspired by code craftsmanship books by Robert Martin and Sandi Metz. I’m not a veteran in writing well-crafted code, but I try my best.
受Robert Martin和Sandi Metz编写的代码技巧书籍的启发,在为该机器人编写代码时,我学会了周到的思想。 我不是编写精心编写的代码的资深人士,但我会尽力而为。
When you do code maintenance in a robot, you can really “love” or “hate” a person that you do not even know just because of the code they have written.
当您在机器人中进行代码维护时,您可以真正“爱”或“恨”一个甚至不仅仅因为他们所写的代码而认识的人。
Messy code almost always goes hand in hand with lower productivity, lower motivation, and a higher number of bugs. Countless hours and significant resources are lost because of poorly written code, but it doesn’t have to be that way.
杂乱的代码几乎总是与较低的生产率,较低的动机和大量的bug并驾齐驱。 由于编写不良的代码而浪费了无数的时间和大量的资源,但这不是必须的。
Clean code is something that’s been on my mind for a while. A year ago, I spoke at Python Conference Philippines about how I made a robot hexapod dance in the effort to practice writing clean code. I spoke about my guiding principles for thoughtfully written code.
干净的代码已经让我想到了一段时间。 一年前,我在菲律宾Python大会上谈到了我如何制作机器人六脚架舞蹈,以练习编写干净的代码。 我谈到了精心编写代码的指导原则。
Even earlier, I wrote about things I think about when I decide to write my own classes. It’s part of my effort to apply an object-oriented design philosophy to make my code clean.
甚至在更早的时候,我就写了一些我决定编写自己的类时所考虑的事情 。 这是我运用面向对象的设计理念来使我的代码整洁的工作的一部分。
I still have these principles and thoughts at the back of my mind whenever I write code in general, and in particular when I wrote the code for Robbie.
每当我编写一般代码时,尤其是当我为Robbie编写代码时,我仍然会想到这些原则和思想。
The code residing in the Arduino section is written in a simplified version of C++ designed for embedded programming. It has two obvious classes, Motors
and DistanceSensors
.
Arduino小节中的代码使用专为嵌入式编程设计的C ++简化版本编写。 它有两个明显的类, Motors
和DistanceSensors
。
The Motors
class is responsible for driving the wheels to make the robot turn left, write, move forward or back.
Motors
类负责驱动轮子以使机器人向左转,书写,前进或后退。
The DistanceSensors
class is responsible for getting the distance and checking if there are obstacles around.
DistanceSensors
类负责获取距离并检查周围是否有障碍物。
There are other classes that I’ve used that were made by other people, such as Serial
and Neopixel
.
我使用了其他人制作的其他类,例如Serial
和Neopixel
。
The code residing in the Raspberry Pi section is written in Python. Some of the classes I’ve written for it are Listener
, Responder
, Directive
, Relayer
, and FaceFinder
.
Raspberry Pi部分中的代码是用Python编写的。 我为此编写的一些类是Listener
, Responder
, Directive
, Relayer
和FaceFinder
。
A Listener
instance is needed to get the phrases (in string format) from the data from the microphone, as interpreted by GoogleSpeech.
一个 根据GoogleSpeech的解释,需要Listener
实例才能从麦克风的数据中获取短语(字符串格式)。
The Responder
plays videos or shows pictures on the screen.
Responder
在屏幕上播放视频或显示图片。
The Directive
processes the phrase to get the word after a keyword that is used to issue commands for the robot to execute.
该Directive
处理短语以在关键字之后获得单词,该关键字用于发出命令以使机器人执行。
The Relayer
communicates with the Arduino.
Relayer
与Arduino通信。
The FaceFinder
is responsible for detecting faces.
FaceFinder
负责检测脸部。
For cleaner code, classes should be responsible for only one thing and nothing more. Classes are created to make things simpler, not complicate things. You know a class is simple when you can describe what it does in one sentence like I just did.
对于更简洁的代码,类仅应负责一件事,仅此而已。 创建类是为了使事情变得简单而不是使事情复杂化。 当您可以像我刚才那样用一个句子描述它的作用时,您就知道一类是简单的。
You need continuous iterations and user feedback to achieve a good user experience for your product.
您需要不断的迭代和用户反馈,才能为您的产品获得良好的用户体验。
Robbie in its current state is only a “minimum viable product”. There are still many things that can be done to improve the reliability, user experience, and overall design of Robbie.
罗比目前的状态只是“最低限度的可行产品”。 要提高Robbie的可靠性,用户体验和整体设计,仍有许多事情可以做。
At the start, we designed Robbie to have various modes (autonomous mode, camera mode, remote control mode, conversation mode), that can be toggled by pushing buttons.
一开始,我们将Robbie设计为具有多种模式( 自主模式, 摄像头模式, 远程控制模式, 对话模式),可以通过按钮进行切换。
But when people started interacting with it, we realized that Robbie was going to be a voice-activated robot 90% of the time. Whenever people encounter Robbie, their instinct is to move towards the robot and talk to it.
但是,当人们开始与之互动时,我们意识到Robbie将有90%的时间成为语音激活的机器人。 每当人们遇到罗比时,他们的本能就是朝机器人走去并与之交谈。
We realized how important it was for Robbie to have a better microphone and better audio speakers, as opposed to adding more sensors for a more reliable obstacle avoidance.
我们意识到,拥有更好的麦克风和更好的音频扬声器对于Robbie而言至关重要,而不是添加更多传感器以更可靠地避开障碍物。
We decided we needed to use a better more powerful omni directional mic. Currently, you have to speak inches above the mic in order to be understood by the robot. So now, the aim is for the robot to understand the commands even if the person is speaking a meter away.
我们决定需要使用更好,功能更强大的全向麦克风。 目前,您必须说出麦克风上方几英寸的距离才能被机器人理解。 因此,现在的目标是即使人在讲话时,机器人也能理解命令。
People get frustrated when Robbie misunderstands. This is very dependent on the sound conditions of the room.
当罗比误解时,人们会感到沮丧。 这非常取决于房间的声音条件。
A conversation goes both ways. Improving the sound system is also one of the main priorities. Depending on the atmosphere of the room, even when Robbie understands the person, the interaction isn’t fun when the person doesn’t understand Robbie.
对话是双向的。 改善音响系统也是主要优先事项之一。 根据房间的气氛,即使Robbie理解了对方,当对方不了解Robbie时,互动也不会很有趣。
We also destroyed batteries because we accidentally left the robot turned on without the battery checker plugged in. The batteries got drained beyond the threshold. This was a very expensive learning experience for us.
我们还销毁了电池,因为我们在没有插入电池检查器的情况下意外地使机器人保持了开机状态。电池电量耗尽,超出了阈值。 对于我们来说,这是一次非常昂贵的学习经历。
The arms of the robot are also a major source of pain. The arms were not mechanically designed properly. They are very fragile, so fragile that mere transportation of the robot would wear them down significantly. Sometimes an arm would fall off and it would be a pain to put it back on.
机器人的手臂也是疼痛的主要来源。 机械臂的机械设计不正确。 它们非常脆弱,非常脆弱,以至于仅仅搬运机器人都会使它们严重磨损。 有时手臂会掉下来,放回去会很痛苦。
We have to design the arm not only to be sturdier but more modular so that it would be easy to put back on if it falls off.
我们不仅要设计坚固的手臂,而且要使其更具模块化,这样,如果摔落,就很容易戴回去。
Speaking of modularity and pain, troubleshooting the electronics of the robot was the most painful process of all. Accessing the electronics was no easy task, because there’s no “easy-access door” and the boards were just drilled all over the place.
说到模块化和痛苦,对机器人的电子设备进行故障排除是所有过程中最痛苦的过程。 接触电子设备绝非易事,因为这里没有“容易接近的门”,而且木板到处都是钻Kong的。
You have to dismantle the head of the 20 kg heavy robot just to get a multimeter inside. It was horrible. I cannot stress this enough. The next time I build a robot, designing for modularity and ease of troubleshooting would be at the top of my priority list. If there is “clean code” there is also “clean electronic integration and assembly”.
您只需要拆下20公斤重的机器人的头部即可使里面有万用表。 那太差了。 我不能太强调这一点。 下次我构建机器人时,优先考虑的是模块化和易于故障排除的设计。 如果有“干净的代码”,那么也有“干净的电子集成和组装”。
Poorly integrated electronics can function. But if things are not thoughtfully assembled or organized, when something goes wrong, nobody will want to fix your robot.
集成不良的电子设备可能会起作用。 但是,如果没有合理地组装或整理东西,当出现问题时,没有人会想要修复您的机器人。
There you have it, my three main insights.
这是我的三个主要见解。
First, it’s easier more than ever to build a sophisticated robot with off-the-shelf parts. This is all thanks to the open-source hardware (OSHW) community. Building a robot is possible because we are standing on the generous shoulders of giants.
首先,构建具有现成零件的复杂机器人比以往任何时候都更加容易。 这一切都要归功于开源硬件(OSHW)社区。 建立机器人是可能的,因为我们站在巨人的慷慨肩膀上。
Second, ideas in designing “clean” code are crucial to building a robot you’ll love and want to work on.
其次,设计“干净”代码的想法对于构建您会喜欢并希望从事的机器人至关重要。
Last but not least, you need to learn through experience, continuous iterations, and user feedback to achieve a good user experience for your products.
最后但并非最不重要的一点是,您需要通过经验,连续迭代和用户反馈来学习,以实现产品的良好用户体验。
I thank my previous employer for giving me the opportunity to grow and work on exciting projects. Being a creative technologist at an advertising agency has truly been a great learning experience.
我感谢我的前任雇主给了我成长和从事令人兴奋的项目的机会。 在广告公司担任创意技术员确实是一次很棒的学习经历。
Credits
学分
翻译自: https://www.freecodecamp.org/news/building-a-voice-activated-robot-for-an-advertising-agency-fedaa9f347d3/
声控助手