zoukankan      html  css  js  c++  java
  • ros实例_百度语音+图灵

    1 百度语音模块

    参考http://blog.csdn.net/u011118482/article/details/55001444

    1.1 百度语音识别包

    git clonehttps://github.com/DinnerHowe/simple_voice.git 

    在catkin下编译

    1.2 安装pyaudio播放器

    sudo apt-get install python-pyaudio 

    1.3 安装python所需环境

    sudo apt-get install vlc

    1.4 测试安装

    roslaunch simple_voicesimple_voice.launch 

    测试语音合成

    rostopic pub /speak_string std_msgs/String-- '请让一下'

    会在home中生成Xbot文件,里面按合成的语句的固定字节截断作为名字存放下载的合成语音。如果两段话前几句相同,会相互覆盖。

    roslaunch simple_voice simple_voice.launch

    1.5 建议

    可以改写成服务比节点好。

    2 图灵聊天机器人模块

    图灵机器人只支持一轮对话,而且不提供sdk,如果有条件可以自己开发聊天机器人。

    目前聊天机器人基本还是模板匹配,依靠检索问答,使用通配符或者文本相似度。

    目前免费,收费版也很便宜,免费版有次数限制。

    1.1 注册

    1.2 机器人个性

    设置一些属性,以及在线训练。

    1.3 私有语料库

    语料库基于相似度匹配,但有时智障,一摸一样的句子,它会回答自己的语料库,而不是你的私有语料库

    1.4 机器人技能

    机器人的一些技能拓展。

    1.5 后台分析

    1.6 图灵聊天机器人原理

    问句输入后,进入筛选器,筛出机器人技能,就是计算和天气之类的,匹配使用文本相似度。中间可以使用一些特定命令进入一些成语接龙游戏。

    以检索式结构为主,应用一些机器学习处理。

    数据来源是爬取的百度知道,百科,可能有各大论坛,和以前人人网小黄鸡的语料。

    3 聊天机器人搭建

    在百度语音包中新建start.py。之后运行

    rosrun baidu_speech start.py

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import rospy
    from std_msgs.msg import String
    from simple_voice.srv import *
    import urllib
    import json
    
    state = 0
    LAN = 0
    file_strs =[]
    
    
    
    def getHtml(url):
        page = urllib.urlopen(url)
        html = page.read()
        return html
    
    
    def listener():
        rospy.Subscriber("Rog_result", String, callback)
    
        rospy.spin()
    
    def str_fix(str):
        global file_strs
        result = ""
        for file_str in file_strs:
            file_strs_left= file_str.split('|')[0]
            strs = file_strs_left.split(',')
            b = True
            for ele in strs:
                if ele not in str:
                    b=False
                    break
            if b:
    	    pub_msg(file_str.split('|')[2])
                return file_str.split('|')[1]
        return str
    def callback(data):
    
        words=data.data
        if words !='识别错误':
            s=get_ans(words) 
            pub.publish(s)
            rospy.loginfo(s)
    
    def get_ans(info):
        key = '###############此处为密钥###################'
        api = 'http://www.tuling123.com/openapi/api?key=' + key + '&info='
        request = api + info
        response = getHtml(request)
        dic_json = json.loads(response)
        result = dic_json['text']
        return result
    
    if __name__ == '__main__':
        rospy.init_node("Main")
        rospy.loginfo('开始')
        pub = rospy.Publisher('speak_string', String, queue_size=10)
    
        # str=raw_input("press to publish")
    listener()   
    

    4 案例源码

    https://github.com/fengmao31/ros-demo




  • 相关阅读:
    向量
    3D坐标系
    Unity坐标系详解
    5G 系统流程系列:AF 的 Traffic Routing Control 以及 UP 路径管理增强
    Git 合并冲突
    撤销 git commit
    Redis NoSQL
    Netflow/IPFIX 流量收集与分析
    Nokia 5GC 产品概览
    通过 OpenAPI 部署 Npcf_PolicyAuthorization-PostAppSessions API Service
  • 原文地址:https://www.cnblogs.com/fengmao31/p/13880216.html
Copyright © 2011-2022 走看看