【语音控制ROS】PocketPhinx语音包的使用<三>

2023-05-16

语音控制机器人

【语音控制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. Rudnicky

The 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 information

The (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 python

import rospy
from geometry_msgs.msg import Twist
from std_msgs.msg import String

class RobotVoiceTeleop:
    #define the constructor of the class
    def  __init__(self):
        #initialize the ROS node with a name voice_teleop
        rospy.init_node('voice_teleop')

        # Publish the Twist message to the cmd_vel topic
        self.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 Hz
        rate = rospy.Rate(5)

        # Initialize the Twist message we will publish.
        self.cmd_vel = Twist()
        #make sure to make the robot stop by default
        self.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 own
        self.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 phrase
        command = msg.data
        if (command in self.commands):
            if command == 'forward':
                self.cmd_vel.linear.x = 0.2
                self.cmd_vel.angular.z = 0.0
            elif command == 'backward':
                self.cmd_vel.linear.x = -0.2
                self.cmd_vel.angular.z = 0.0
            elif command == 'turn left':
                self.cmd_vel.linear.x = 0.0
                self.cmd_vel.angular.z = 0.5
            elif command == 'turn right':
                self.cmd_vel.linear.x = 0.0
                self.cmd_vel.angular.z = -0.5
            elif command == 'stop':
                self.cmd_vel.linear.x = 0.0
                self.cmd_vel.angular.z = 0.0

        else: #command not found
            #print 'command not found: '+command
            self.cmd_vel.linear.x = 0.0
            self.cmd_vel.angular.z = 0.0
        print ("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 语音决定机器人是否接收语音

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐

  • 【python安全攻防】python简易端口扫描器

    文章目录 socket套接字optparse模块socket解析主机进行连接获取bannerthreading多线程端口扫描器python nmap端口扫描 对自己看python绝技的一次学习记录 socket套接字 与TCP端口进行交互
  • EsLint 常用规则

    ESLint 是一个代码规范和错误检查工具 xff0c 有以下几个特性 所有东西都是可以插拔的 你可以调用任意的 rule api 或者 formatter api 去打包或者定义 rule or formatter 任意的 rule 都是
  • qt 手动释放new出堆中的内存,如何释放什么时候释放,qt和c++中使用delete的不同

    http www 360doc com content 20 1019 10 65283686 941181306 shtml
  • C++:error C4996解决方法

    背景 使用fopen sprintf strcpy strstr 等函数 xff0c 在编译c 43 43 程序时报如下错 xff1a error C4996 strncat This function or variable may be
  • call(zoom)_如何解决您的Zoom Call问题

    call zoom A lot of people and businesses have turned to Zoom as their go to video conferencing application However Zoom
  • Nginx配置访问密码(在线|离线安装)

    Nginx配置访问密码 在线 xff5c 离线安装 实现效果 xff1a 1 通过nignx访问的站点或目录 xff0c 需要让用户输入用户名密码才能访问 2 在nginx下 xff0c 提供了ngx http auth basic mod
  • linux下docker安装rabbitmq无法打开控制台

    文章目录 一 安装rabbitmq xff0c 并启动二 访问三 解决问题 linux下使用docker安装rabbitmq后 xff0c 无法访问控制台 xff0c 已解决 一 安装rabbitmq xff0c 并启动 1 拉取镜像 do
  • Wake On Lan(WOL)失败的原因

    Wake On Lan xff0c 失败的原因 发送Magic Packet xff08 魔法数据包 xff09 xff0c 不多阐述 xff0c 如果是编程发包 xff0c 请使用UDP封包 在BIOS中开启 Wake On Lan 选项
  • spring的配置文件

    使用流程 添加spring依赖创建类创建spring配置文件 xff0c 并在配置文件中给要被spring创建和管理的类添加标识 在主程序中加载spring配置文件从容器中获取对象 bean的配置 在spring配置文件中 xff0c 通过
  • 解决vc++运行窗口一闪而过的方法

    1 可以在程序添加头文件 include lt Windows h gt 然后在main函数最后的 return 0 xff1b 前面加上system pause xff1b 2 不要手动按运行键 xff0c 而用快捷键ctrl 43 f5
  • centos 6升级内核小版本、更新yum源和升级gcc版本

    文章目录 前言一 升级内核小版本1 1 设置开机自启动网卡1 2 下载待升级内核小版本的rpm文件1 3 修改内核版本启动顺序 二 更换yum源三 升级g 43 43 版本参考链接 前言 将centos 6 8 2 6 32 642 el6
  • 【PX4_BUG】jMAVSim仿真找不到libawt_xawt.so和libjawt.so文件或jdk版本不匹配的解决方法

    在使用make px4 sitl jmavsim命令进行仿真时出现错误 java lang UnsatisfiedLinkError Can 39 t load library usr lib jvm java 11 openjdk amd
  • Windows Server 2016域控服务器如何取消密码复杂性规则

    图 1 报错截图 具体解决办法 第一步 打开服务器管理 如图直接在 放大镜搜索框里面 直接输入搜索服务器管理或者打开箭头3所示的图标 第二步 点击工具 打开组策略管理 第三步 找到 Default Domain Policy 然后鼠标右击编
  • noVNC搭建

    noVNC搭建 1 环境准备 Os centos7 5准备两台设备 192 168 17 176 和 192 168 17 177 2 安装python环境 安装python3 在192 168 17 176操作如下 查看之前是否存在环境
  • Arduino小项目1---esp8266 WiFi 签到机

    Arduino小项目1 ESP8266 WiFi 签到机 前言0 使用的材料和软件1 准备一个HTML网页A 搭建出适合手机的页面框架B 在body中加入表单元素form标签 xff1a 它的常用属性是action xff0c 就是把表单提
  • 如何找回忘记的Facebook密码

    If you don t use a password manager those complex passwords can be pretty hard to remember If you ve forgotten your Face
  • Cube-SLAM编译遇到的问题

    error iota was not declared in this scope 解决办法 xff1a 报错位置添加 xff1a span class token macro property span class token direc
  • CubeSLAM学习

    Cube SLAM 此代码包含两种模式 xff1a 与ORB SLAM集成的对象SLAM 请参见orb object slam具有ros bag输入的在线SLAM 读取离线检测到的3D对象仅适用于多维数据集SLAM的基本实现 参见objec
  • [转载]PAC模式与全局模式的区别

    区别一 xff1a 使用流量多少不一样 PAC模式 xff1a 节省流量 全局模式 xff1a 流量消耗较多 区别二 xff1a 运行速度快慢不一样 PAC模式 xff1a 国内网站依旧走本地网络 xff0c 速度快 xff0c 绝大部分国
  • 【语音控制ROS】PocketPhinx语音包的使用<三>

    语音控制机器人 语音控制ROS 虚拟机安装Ubuntu14 04 43 ROS indigo xff1c 一 xff1e 语音控制ROS 仿真环境的搭建 xff1c 二 xff1e 用语音来控制机器人移动 前提 xff1a 安装好了ROS环