语音控制机器人

【语音控制ROS】虚拟机安装Ubuntu14.04+ROS-indigo<一>
【语音控制ROS】仿真环境的搭建<二>

用语音来控制机器人移动

前提:安装好了ROS环境 14.04+indigo

1、安装PocketSphinx语音识别

安装如下环境

sudo apt-get install gstreamer0.10-pocketsphinx
sudo apt-get install ros-indigo-pocketsphinx
sudo apt-get install ros-indigo-audio-common
sudo apt-get install libasound2

2、测试 PocketSphinx的语音功能

最好有个usb的麦克风,并且测试是否有声音输入

pocketsphinx 是ROS Indigo中 的一个功能包. 更多的细节在ROS WIKIpocketsphinx package .
进入 pocketsphinx 功能包

roscd pocketsphinx

在目录 demo/, 我们能找到 voice commands and dictionary,可以用more/cat/nano查看

接下来启动robocup.launch文件

roslaunch pocketsphinx robocup.launch

文件robocup.launch如下

<launch><node name="recognizer" pkg="pocketsphinx" type="recognizer.py" output="screen"><param name="lm" value="$(find pocketsphinx)/demo/robocup.lm"/><param name="dict" value="$(find pocketsphinx)/demo/robocup.dic"/></node>
</launch>

启动了 recognizer.py 脚本来运行 robocup.dic. 加载语音识别模型。启动成功为如下界面

INFO: ngram_search_fwdtree.c(186): Creating search tree
INFO: ngram_search_fwdtree.c(191): before: 0 root, 0 non-root channels, 12 single-phone words
INFO: ngram_search_fwdtree.c(326): after: max nonroot chan increased to 328
INFO: ngram_search_fwdtree.c(338): after: 77 root, 200 non-root channels, 11 single-phone words

接下来,对着麦克风说话

hello
go to the room
my name is
door
follow room

我们说的话是话题 /recognizer/output

rostopic echo /recognizer/output

可以看到输出的效果

data: go to the room
--
data: hello
--

3、创建工作区

创建工作区~/catkin_ws/src/
创建功能包 voice_robot 并且添加依赖 pocketsphinx, roscpp, rospy, sound_play and std_msgs

catkin_create_pkg voice_robot roscpp rospy pocketsphinx sound_play std_msgs
$ cd ~/catkin_ws
~/catkin_ws & catkin_make

4、创建语音命令

添加“ PocketSphinx”中指定的词汇或语料库。 创建一个简单的命令词汇表,以使Turtlebot机器人向前,向后移动以及向左和向右旋转。

4.1 voice_robot下创建目录config

创建文件 motion_commands.txt 输入以下内容

move forward
move backwards
turn right
turn left

创建文件motion_commands.lm输入以下内容

Language model created by QuickLM on Wed Jun 15 13:21:57 EDT 2016
Copyright (c) 1996-2010 Carnegie Mellon University and Alexander I. RudnickyThe model is in standard ARPA format, designed by Doug Paul while he was at MITRE.The code that was used to produce this language model is available in Open Source.
Please visit http://www.speech.cs.cmu.edu/tools/ for more informationThe (fixed) discount mass is 0.5. The backoffs are computed using the ratio method.
This model based on a corpus of 5 sentences and 9 words\data\
ngram 1=9
ngram 2=12
ngram 3=9\1-grams:
-0.8808 </s> -0.3010
-0.8808 <s> -0.2398
-1.5798 BACKWARD -0.2398
-1.5798 FORWARD -0.2398
-1.5798 LEFT -0.2398
-1.2788 MOVE -0.2775
-1.5798 RIGHT -0.2398
-1.5798 STOP -0.2398
-1.2788 TURN -0.2775\2-grams:
-0.6990 <s> MOVE 0.0000
-1.0000 <s> STOP 0.0000
-0.6990 <s> TURN 0.0000
-0.3010 BACKWARD </s> -0.3010
-0.3010 FORWARD </s> -0.3010
-0.3010 LEFT </s> -0.3010
-0.6021 MOVE BACKWARD 0.0000
-0.6021 MOVE FORWARD 0.0000
-0.3010 RIGHT </s> -0.3010
-0.3010 STOP </s> -0.3010
-0.6021 TURN LEFT 0.0000
-0.6021 TURN RIGHT 0.0000\3-grams:
-0.6021 <s> MOVE BACKWARD
-0.6021 <s> MOVE FORWARD
-0.3010 <s> STOP </s>
-0.6021 <s> TURN LEFT
-0.6021 <s> TURN RIGHT
-0.3010 MOVE BACKWARD </s>
-0.3010 MOVE FORWARD </s>
-0.3010 TURN LEFT </s>
-0.3010 TURN RIGHT </s>\end\

创建文件motion_commands.dic并输入以下内容

BACKWARD B AE K W ER D
FORWARD F AO R W ER D
LEFT    L EH F T
MOVE    M UW V
RIGHT   R AY T
STOP    S T AA P
TURN    T ER N

4.2 voice_robot下创建launch目录

并创建 recognizer.launch

 <launch><node name="recognizer" pkg="pocketsphinx" type="recognizer.py" output="screen"><param name="lm" value="$(find voice_robot)/config/motion_commands.lm"/><param name="dict" value="$(find voice_robot)/config/motion_commands.dic"/></node>
</launch>

启动launch文件 recognizer.launch

roslaunch voice_robot recognizer.launch

对着麦克风说话,观察输出

rostopic echo /recognizer/output

正常输出,接着下一步,控制机器人

5、Voice-Control的脚本

5.1 创建script目录

创建 voice_teleop.py

#!/usr/bin/env pythonimport rospy
from geometry_msgs.msg import Twist
from std_msgs.msg import Stringclass RobotVoiceTeleop:#define the constructor of the classdef  __init__(self):#initialize the ROS node with a name voice_teleoprospy.init_node('voice_teleop')# Publish the Twist message to the cmd_vel topicself.cmd_vel_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=5)# Subscribe to the /recognizer/output topic to receive voice commands.rospy.Subscriber('/recognizer/output', String, self.voice_command_callback)#create a Rate object to sleep the process at 5 Hzrate = rospy.Rate(5)# Initialize the Twist message we will publish.self.cmd_vel = Twist()#make sure to make the robot stop by defaultself.cmd_vel.linear.x=0;self.cmd_vel.angular.z=0;# A mapping from keywords or phrases to commands#we consider the following simple commands, which you can extend on your ownself.commands =             ['stop','forward','backward','turn left','turn right',]rospy.loginfo("Ready to receive voice commands")# We have to keep publishing the cmd_vel message if we want the robot to keep moving.while not rospy.is_shutdown():self.cmd_vel_pub.publish(self.cmd_vel)rate.sleep()def voice_command_callback(self, msg):# Get the motion command from the recognized phrasecommand = msg.dataif (command in self.commands):if command == 'forward':self.cmd_vel.linear.x = 0.2self.cmd_vel.angular.z = 0.0elif command == 'backward':self.cmd_vel.linear.x = -0.2self.cmd_vel.angular.z = 0.0elif command == 'turn left':self.cmd_vel.linear.x = 0.0self.cmd_vel.angular.z = 0.5elif command == 'turn right':self.cmd_vel.linear.x = 0.0self.cmd_vel.angular.z = -0.5elif command == 'stop':self.cmd_vel.linear.x = 0.0self.cmd_vel.angular.z = 0.0else: #command not found#print 'command not found: '+commandself.cmd_vel.linear.x = 0.0self.cmd_vel.angular.z = 0.0print ("linear speed : " + str(self.cmd_vel.linear.x))print ("angular speed: " + str(self.cmd_vel.angular.z))if __name__=="__main__":try:RobotVoiceTeleop()rospy.spin()except rospy.ROSInterruptException:rospy.loginfo("Voice navigation terminated.")

新建launch文件voice_control_in_stage.launch

 <launch><node name="recognizer" pkg="pocketsphinx" type="recognizer.py" output="screen"><param name="lm" value="$(find voice_robot)/config/motion_commands.lm"/><param name="dict" value="$(find voice_robot)config/motion_commands.dic"/></node><node name="voice_teleop" pkg="voice_robot" type="voice_teleop.py" output="screen"><remap from="/cmd_vel" to="/cmd_vel_mux/input/teleop"/></node><include file="$(find turtlebot_stage)/launch/turtlebot_in_stage.launch"/>
</launch>

使用gazebo仿真的话,最后一句换为以下代码

<launch>
...<include file="$(find turtlebot_gazebo)/launch/turtlebot_world.launch"/>
</launch>

6 测试

启动launch文件

roslaunch voice_robot voice_control_in_stage.launch

相当于下面三句话

roslaunch voice_robot recognizer.launch
rosrun voice_robot voice_teleop.py
roslaunch turtlebot_stage turtlebot_in_stage.launch

对着麦克风说话测试成功

7 可继续做的工作

7.1 扩展词汇

7.2 语音决定机器人是否接收语音

【语音控制ROS】PocketPhinx语音包的使用<三>相关推荐

  1. python3语音识别模块_零基础教你玩转语音控制,学习语音控制技术,打造智能生活很简单...

    大家好,我是阿乐,今天给大家讲解一下LD3320语音识别模块. 先来看看模块实物,它是长这个样子的: LD3320语音识别模块实物 我现在用来给大家做讲解的这个模块是已经集成了单片机在上面,这样子开发 ...

  2. python3语音控制电脑_python语音控制电脑_uusee全屏

    # -*- coding: utf-8 -*- import time import speech import subprocess import win32com.client from zoom ...

  3. 开发者说 | AI操控机器人系列第三期——语音控制(另附直播预约通道)

    预约通道: 课程正文: 摘要: 在AI操控机器人系列第二期的人体跟随教程中,身为地平线资深程序员的奶爸朱靠,使用地平线发布的机器人开发平台TogetherROS软件栈,搭建了人体跟随机器人. 同为开发 ...

  4. DIY 智能家居语音助理 —— 语音控制万物

    本文作者:默. 开源电子平台兴起以来,诞生了不少的创客们,他们用天马行空的想象力,创造出各种新鲜有趣的作品,他们热衷于改变千篇一律的生活,享受科技创造带来的乐趣.其中与我们的生活息息相关的就包括智能家 ...

  5. 基于Blinker的小爱同学语音控制【脱坑指南】

    基于Blinker的小爱同学语音控制ESP8266 前些天在使用esp8266时遇到很多小爱不能控制设备问题,现在来叙述我控制过程中所遇到的问题,以及到完整的小爱能成功控制Esp8266的过程. 1. ...

  6. ROS探索总结(十)(十一)(十二)——语音控制 机器视觉 坐标系统

    ROS探索总结(十)--语音控制 如今语音识别在PC机和智能手机上炒的火热,ROS走在技术的最前沿当然也不会错过这么帅的技术.ROS中使用了CMU Sphinx和Festival开源项目中的代码,发布 ...

  7. ros机器人编程实践(15.2)- 使用科大讯飞语音控制turtlebot导航

    一.前言 接上一篇博客:ros机器人编程实践(15.1)- 使用科大讯飞语音控制turtlebot导航 二.使用科大讯飞语音SDK 对着上一篇博客中科大讯飞的安装教程,创建了robot_voice的基 ...

  8. ROS语音控制——小乌龟按设定图形路线运动

    最近几天在学习语音识别.语音合成,应用到ROS当中实现一些简单的案例,下面是使用语音来控制turtle小乌龟走设定图形路线的案例. ROS小乌龟走设定图形路线(键盘控制+Python代码实现)_笨小古 ...

  9. 基于ROS的语音控制机器人(一):基本功能的实现

    文章目录 目录 文章目录 前言 一.ubuntu16.04和树莓派安装ROS-kinetic 二.树莓派和PC机之间的ros通信 1.修改环境变量 2.数据通信 三.科大讯飞sdk下载 四.树莓派和S ...

最新文章

  1. pytorch遇见RuntimeError: CUDA out of memory的解决
  2. Effective C#: Item 1 Always use properties instead of accessible data members
  3. android中高德地图轨迹回放,轨迹回放-点标记-示例中心-JS API 2.0 示例 | 高德地图API...
  4. [Leetcode] Remove duplicates from sorted array ii 从已排序的数组中删除重复元素
  5. 1059 Prime Factors (25 分)【难度: 一般 / 知识点: 分解质因子 】
  6. java 导出word换行_Java 导出数据库表信息生成Word文档
  7. 【渝粤教育】 国家开放大学2020年春季 2246社会工作概论 参考试题
  8. 密度聚类dbscan_DBSCAN —基于密度的聚类方法的演练
  9. 【Android自定义控件】圆圈交替,仿progress效果
  10. java 中常见的文件上传方式_java中如何上传文件
  11. CoVaR计算手册-动态CoVaR模型-数据、代码、步骤
  12. STM32单片机初学1-STM32介绍
  13. 读后感系列-2.《看见》柴静(二)
  14. 微信商户平台 扣款测试规则
  15. 自然人如何在浙江法院网上完成诉讼——具体流程
  16. Ubuntu 20.04 多GPU,涡轮GPU 风扇转速手动调节
  17. HBuilder封装APP
  18. Linux服务器之间使用scp免密传输文件
  19. 人工智能的发展历程,AI ,路在何方(文章分享)
  20. 报名网站html代码,考试报名系统 附源码

热门文章

  1. vivado查看内部资源占用情况
  2. 网易云音乐爬虫 数据可视化分析
  3. 中文拼音首字母排序比较器
  4. 又一年的五一劳动节!
  5. 阿里云亮眼财报背后,云的打开方式正在重塑
  6. Linux常用命令 实用命令万字总结(转载学习)
  7. 如何给Mac挑选外接显示器?苹果外接显示器选购指南
  8. 数据库:一条sql语句查询每门课程都大于80分的学生姓名
  9. 穿西服和穿皮鞋有那些讲究?
  10. 计算机评游戏图形低,5常见的PC游戏图形选项说明 | MOS86