• 大小: 13KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-05-19
  • 语言: 其他
  • 标签:

资源简介

ROS结合科大讯飞的语音识别包,第一版。使用的是catkin workspace。包括语音识别,语音介绍,语音合成,语音唤醒。可能需要某些库的支持,

资源截图

代码片段和文件信息

#!/usr/bin/env python
#coding=utf-8
import rospy
from std_msgs.msg import String
import demjson
import time 
import os
import sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)

pub = rospy.Publisher(‘xfsaywords‘ String queue_size=10)
pub_cmd = rospy.Publisher(‘/control_cmd‘ String queue_size=10)
rospy.init_node(‘explainer‘)
rate = rospy.Rate(10)
rate.sleep()
def say(mystr):
    rate.sleep()
    pub.publish(mystr)
    print(“I will say:%s“%(mystr))
def sendcmd(mycmd):
    rate.sleep()
    pub_cmd.publish(mycmd)
    print(“I will say:%s“%(mycmd))
def callback(data):
    s1=““
    openQAState = False
    openQACommend = ‘‘ #存储问答得到的命令

    MusicPalyCommed = ‘‘
    MusicAvailable = False
    result=demjson.decode(data.data)
    print data.data
    if(result.has_key(“service“)):
        service=result[“service“]
        if(service==“chat“):
            s1 = result[“answer“][“text“]
        elif(service==“music“):
            s1+=u“接下来播放“+\
                    result[“data“][“result“][0][“singer“]+\
                    u“的“+\
                    result[“data“][“result“][0][“name“]
            MusicPlayCommend = ‘echo loadfile ‘+\
                    result[“data“][“result“][0][“downloadUrl“]+\
                    ‘>/Robot/cmd/Mplayer_cmd‘
           # print MusicPlayCommend
            MusicAvailable = True
        elif(service==“openQA“):
            for letter in result[“answer“][“text“]:
                if(openQAState == True):
                    openQACommend = letter
                    openQAState = False
                if(letter == ‘<‘):
                    openQAState = True
            for letter in result[“answer“][“text“]:
                if(letter==‘<‘):
                    break
                s1 += letter
            print openQACommend
            sendcmd(openQACommend)
        elif(service==“datetime“ or service==“calc“ or service==“baike“ or service== “faq“):
            s1 = result[“answer“][“text“]
        elif(service==“schedule“):
            s1 = u“正在创建提醒事项... ...好的我会提醒你“
                   # result[“semantic“][“slots“][“datatime“][“dateOrig“]+\
                   # result[“semantic“][“content“][“datatime“][“timeOrig“]
                    
    say(s1)
    if(MusicAvailable):
        time.sleep(1)
        os.system(MusicPlayCommend)
        MusicAvailable = False

if __name__ == ‘__main__‘:
    try:
        rospy.Subscriber(“xfunderstand“ String callback)
        say(u“语音解释初始化成功“)
        rospy.spin()
    except rospy.ROSInterruptException:
        pass

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-07-19 16:15  xf_voice\
     文件         841  2016-07-10 12:01  xf_voice\CMakeLists.txt
     文件       18892  2016-07-19 16:15  xf_voice\CMakeLists.txt.user
     目录           0  2016-07-09 22:39  xf_voice\include\
     目录           0  2016-07-09 22:39  xf_voice\include\xf_voice\
     文件        2108  2016-07-09 22:39  xf_voice\package.xml
     目录           0  2016-07-19 16:13  xf_voice\src\
     文件        2597  2016-07-12 12:37  xf_voice\src\explain.py
     文件        1869  2016-07-10 09:53  xf_voice\src\wakeup.cpp
     文件       15506  2016-07-19 16:13  xf_voice\src\xf_asr.cpp
     文件        5948  2016-07-13 01:10  xf_voice\src\xf_tts.cpp

评论

共有 条评论

相关资源