胡笨笨硕士期间项目心得之项目三-二气象知识图谱语音问答系统

项目场景:

对于知识图谱落地还有一个便是问答系统,目前就是基于文字输入再文字输出,但是我们可以玩点花活基于语音的知识图谱问答系统。


知识图谱构建(略)

在项目三中,已经搭建了气象知识图谱,可以参考前面博客。


关键信息提取:

在接入语音识别之前,先要做的是假设识别出一句语句那么应该要怎么处理,以前基于知识图谱的问答系统,是用模板匹配,但是我个人觉得效果并不好而且要输入特定的语句,文字输入可以,但是话术的化误差性大,就不适合了。那要用什么方法呢,为此,我想了一下,在不考虑兼容和可扩展性的情况下,我采取了直接莽上去的方法,就是利用python 里面find语句找到里面关键词,这是必然有缺点的,例如语义的转折,或同义词出现,这些还在搞,目前版本是最简单的,将几个同义词放到一起(这个可以用txt文本做可扩容)但是还是那句时间紧任务重,先做一个出来,之后在做添加。为此,方案就有了,下面就是简单的码代码,做这个简单的功能模块。代码如下

__author__ = "Huzhichen"
#coding=utf-8
import json
from py2neo import Graph, Node, Relationship, cypher, NodeMatcher, RelationshipMatcher
graph = Graph("http://localhost:7474", auth=("neo4j", "admin"))
matcher = NodeMatcher(graph)
sentence='降雨预警紫色降雨学校预防措施'
answerStence=''
if sentence.find('雨')!=-1 :
    if sentence.find('蓝色')!=-1:
        if sentence.find('措施')!=-1 or sentence.find('预防措施')!=-1 or sentence.find('方法')!=-1 or sentence.find('预防方法')!=-1 or sentence.find('防汛')!=-1:
            if sentence.find('学校')!=-1 or sentence.find('大学')!=-1 or sentence.find('本科')!=-1 or sentence.find('高中')!=-1 or sentence.find('初中')!=-1 or sentence.find('小学')!=-1 or sentence.find('小学')!=-1 or sentence.find('幼儿园')!=-1:
                ret = graph.run('MATCH p=(n:`蓝色预警`{name:"暴雨蓝色预警"})-[*]->(m:`学校`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence=nodes['content']
                print(answerStence)
            elif sentence.find('政府')!=-1:
                ret = graph.run('MATCH p=(n:`蓝色预警`{name:"暴雨蓝色预警"})-[*]->(m:`政府`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('户外人员')!=-1 or sentence.find('户外工作者')!=-1:
                ret = graph.run('MATCH p=(n:`蓝色预警`{name:"暴雨蓝色预警"})-[*]->(m:`户外人员`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('城管部门')!=-1:
                ret = graph.run('MATCH p=(n:`蓝色预警`{name:"暴雨蓝色预警"})-[*]->(m:`城管部门`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            else:
                f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
                f1.write(sentence + '\n')
                print("保存成功")
                f1.close()
                answerStence = '抱歉,我还不会,真正学习中!'
                #print(answerStence)
        elif sentence.find('降雨量')!=-1 or sentence.find('雨量')!=-1:
            ret = graph.run('MATCH p=(n:`蓝色预警`{name:"暴雨蓝色预警"})-[*]->(m:`级别标准`) return m').data()
            nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
            nodes = json.loads(nodesStr)
            answerStence = nodes['name']
            print(answerStence)
        else:
            f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
            f1.write(sentence + '\n')
            print("保存成功")
            f1.close()
            answerStence = '抱歉,我还不会,真正学习中!'
            #print(answerStence)
    elif sentence.find('黄色')!=-1:
        if sentence.find('措施') != -1 or sentence.find('预防措施') != -1 or sentence.find('方法') != -1 or sentence.find('预防方法') != -1 or sentence.find('防汛') != -1:
            if sentence.find('学校') != -1 or sentence.find('大学') != -1 or sentence.find('本科') != -1 or sentence.find('高中') != -1 or sentence.find('初中') != -1 or sentence.find('小学') != -1 or sentence.find('小学') != -1 or sentence.find('幼儿园') != -1:
                ret = graph.run('MATCH p=(n:`黄色预警`{name:"暴雨黄色预警"})-[*]->(m:`学校`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('政府') != -1:
                ret = graph.run('MATCH p=(n:`黄色预警`{name:"暴雨黄色预警"})-[*]->(m:`政府`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('户外人员') != -1 or sentence.find('户外工作者') != -1:
                ret = graph.run('MATCH p=(n:`黄色预警`{name:"暴雨黄色预警"})-[*]->(m:`户外人员`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('城管部门') != -1:
                ret = graph.run('MATCH p=(n:`黄色预警`{name:"暴雨黄色预警"})-[*]->(m:`城管部门`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            else:
                f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
                f1.write(sentence + '\n')
                print("保存成功")
                f1.close()
                answerStence = '抱歉,我还不会,真正学习中!'
                #print(answerStence)
        elif sentence.find('降雨量')!=-1 or sentence.find('雨量')!=-1:
            ret = graph.run('MATCH p=(n:`黄色预警`{name:"暴雨黄色预警"})-[*]->(m:`级别标准`) return m').data()
            nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
            nodes = json.loads(nodesStr)
            answerStence = nodes['name']
            print(answerStence)
        else:
            f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
            f1.write(sentence + '\n')
            print("保存成功")
            f1.close()
            answerStence = '抱歉,我还不会,真正学习中!'
            #print(answerStence)
    elif sentence.find('橙色')!=-1:
        if sentence.find('措施') != -1 or sentence.find('预防措施') != -1 or sentence.find('方法') != -1 or sentence.find('预防方法') != -1 or sentence.find('防汛') != -1:
            if sentence.find('学校') != -1 or sentence.find('大学') != -1 or sentence.find('本科') != -1 or sentence.find('高中') != -1 or sentence.find('初中') != -1 or sentence.find('小学') != -1 or sentence.find('小学') != -1 or sentence.find('幼儿园') != -1:
                ret = graph.run('MATCH p=(n:`橙色预警`{name:"暴雨橙色预警"})-[*]->(m:`学校`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('政府') != -1:
                ret = graph.run('MATCH p=(n:`橙色预警`{name:"暴雨橙色预警"})-[*]->(m:`政府`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('户外人员') != -1 or sentence.find('户外工作者') != -1:
                ret = graph.run('MATCH p=(n:`橙色预警`{name:"暴雨橙色预警"})-[*]->(m:`户外人员`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('城管部门') != -1:
                ret = graph.run('MATCH p=(n:`橙色预警`{name:"暴雨橙色预警"})-[*]->(m:`城管部门`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            else:
                f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
                f1.write(sentence + '\n')
                print("保存成功")
                f1.close()
                answerStence = '抱歉,我还不会,真正学习中!'
                #print(answerStence)
        elif sentence.find('降雨量')!=-1 or sentence.find('雨量')!=-1:
            ret = graph.run('MATCH p=(n:`橙色预警`{name:"暴雨橙色预警"})-[*]->(m:`级别标准`) return m').data()
            nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
            nodes = json.loads(nodesStr)
            answerStence = nodes['name']
            print(answerStence)
        else:
            f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
            f1.write(sentence + '\n')
            print("保存成功")
            f1.close()
            answerStence = '抱歉,我还不会,真正学习中!'
            #print(answerStence)
    elif sentence.find('红色')!=-1:
        if sentence.find('措施') != -1 or sentence.find('预防措施') != -1 or sentence.find('方法') != -1 or sentence.find('预防方法') != -1 or sentence.find('防汛') != -1:
            if sentence.find('学校') != -1 or sentence.find('大学') != -1 or sentence.find('本科') != -1 or sentence.find('高中') != -1 or sentence.find('初中') != -1 or sentence.find('小学') != -1 or sentence.find('小学') != -1 or sentence.find('幼儿园') != -1:
                ret = graph.run('MATCH p=(n:`红色预警`{name:"暴雨红色预警"})-[*]->(m:`学校`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('政府') != -1:
                ret = graph.run('MATCH p=(n:`红色预警`{name:"暴雨红色预警"})-[*]->(m:`政府`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('城管部门') != -1:
                ret = graph.run('MATCH p=(n:`红色预警`{name:"暴雨红色预警"})-[*]->(m:`城管部门`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            else:
                f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
                f1.write(sentence + '\n')
                print("保存成功")
                f1.close()
                answerStence = '抱歉,我还不会,真正学习中!'
                #print(answerStence)
        elif sentence.find('降雨量')!=-1 or sentence.find('雨量')!=-1:
            ret = graph.run('MATCH p=(n:`红色预警`{name:"暴雨红色预警"})-[*]->(m:`级别标准`) return m').data()
            nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
            nodes = json.loads(nodesStr)
            answerStence = nodes['name']
            print(answerStence)
        else:
            f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
            f1.write(sentence + '\n')
            print("保存成功")
            f1.close()
            answerStence = '抱歉,我还不会,真正学习中!'
            #print(answerStence)
    else:
        f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
        f1.write(sentence + '\n')
        print("保存成功")
        f1.close()
        answerStence = '抱歉,我还不会,真正学习中!'
else:
    f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
    f1.write(sentence + '\n')
    print("保存成功")
    f1.close()
    answerStence = '抱歉,我还不会,真正学习中!'
print(answerStence)

语音问答:

这里我是参考了这个博客“从零开始搭建一个语音对话机器人”传送门这里有一个提醒就是安装ffmpeg时候路径中不能有一个中文,不能有中文,不能有中文,别问我是怎么知道的。
最后将两者融合进行识别。

from aip import AipSpeech
import pyrec
import wav2pcm
import  playmp3
import json
from py2neo import Graph, Node, Relationship, cypher, NodeMatcher, RelationshipMatcher
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
pyrec.rec('Weather.wav')
pcm_file=wav2pcm.wav_to_pcm('Weather.wav')
with open('Weather.pcm','rb') as fp:
    file_context=fp.read()
# 识别本地语音
res=client.asr(file_context,'pcm',16000,{
    'dev_pid':1536,
})
graph = Graph("http://localhost:7474", auth=("neo4j", "admin"))
matcher = NodeMatcher(graph)
sentence=res['result'][0]
print(sentence)
answerStence=''
if sentence.find('雨')!=-1 :
    if sentence.find('蓝色')!=-1:
        if sentence.find('措施')!=-1 or sentence.find('预防措施')!=-1 or sentence.find('方法')!=-1 or sentence.find('预防方法')!=-1 or sentence.find('防汛')!=-1:
            if sentence.find('学校')!=-1 or sentence.find('大学')!=-1 or sentence.find('本科')!=-1 or sentence.find('高中')!=-1 or sentence.find('初中')!=-1 or sentence.find('小学')!=-1 or sentence.find('小学')!=-1 or sentence.find('幼儿园')!=-1:
                ret = graph.run('MATCH p=(n:`蓝色预警`{name:"暴雨蓝色预警"})-[*]->(m:`学校`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence=nodes['content']
                print(answerStence)
            elif sentence.find('政府')!=-1:
                ret = graph.run('MATCH p=(n:`蓝色预警`{name:"暴雨蓝色预警"})-[*]->(m:`政府`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('户外人员')!=-1 or sentence.find('户外工作者')!=-1:
                ret = graph.run('MATCH p=(n:`蓝色预警`{name:"暴雨蓝色预警"})-[*]->(m:`户外人员`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('城管部门')!=-1:
                ret = graph.run('MATCH p=(n:`蓝色预警`{name:"暴雨蓝色预警"})-[*]->(m:`城管部门`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            else:
                f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
                f1.write(sentence + '\n')
                print("保存成功")
                f1.close()
                answerStence = '抱歉,我还不会,真正学习中!'
                #print(answerStence)
        elif sentence.find('降雨量')!=-1 or sentence.find('雨量')!=-1:
            ret = graph.run('MATCH p=(n:`蓝色预警`{name:"暴雨蓝色预警"})-[*]->(m:`级别标准`) return m').data()
            nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
            nodes = json.loads(nodesStr)
            answerStence = nodes['name']
            print(answerStence)
        else:
            f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
            f1.write(sentence + '\n')
            print("保存成功")
            f1.close()
            answerStence = '抱歉,我还不会,真正学习中!'
            #print(answerStence)
    elif sentence.find('黄色')!=-1:
        if sentence.find('措施') != -1 or sentence.find('预防措施') != -1 or sentence.find('方法') != -1 or sentence.find('预防方法') != -1 or sentence.find('防汛') != -1:
            if sentence.find('学校') != -1 or sentence.find('大学') != -1 or sentence.find('本科') != -1 or sentence.find('高中') != -1 or sentence.find('初中') != -1 or sentence.find('小学') != -1 or sentence.find('小学') != -1 or sentence.find('幼儿园') != -1:
                ret = graph.run('MATCH p=(n:`黄色预警`{name:"暴雨黄色预警"})-[*]->(m:`学校`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('政府') != -1:
                ret = graph.run('MATCH p=(n:`黄色预警`{name:"暴雨黄色预警"})-[*]->(m:`政府`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('户外人员') != -1 or sentence.find('户外工作者') != -1:
                ret = graph.run('MATCH p=(n:`黄色预警`{name:"暴雨黄色预警"})-[*]->(m:`户外人员`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('城管部门') != -1:
                ret = graph.run('MATCH p=(n:`黄色预警`{name:"暴雨黄色预警"})-[*]->(m:`城管部门`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            else:
                f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
                f1.write(sentence + '\n')
                print("保存成功")
                f1.close()
                answerStence = '抱歉,我还不会,真正学习中!'
                #print(answerStence)
        elif sentence.find('降雨量')!=-1 or sentence.find('雨量')!=-1:
            ret = graph.run('MATCH p=(n:`黄色预警`{name:"暴雨黄色预警"})-[*]->(m:`级别标准`) return m').data()
            nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
            nodes = json.loads(nodesStr)
            answerStence = nodes['name']
            print(answerStence)
        else:
            f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
            f1.write(sentence + '\n')
            print("保存成功")
            f1.close()
            answerStence = '抱歉,我还不会,真正学习中!'
            #print(answerStence)
    elif sentence.find('橙色')!=-1:
        if sentence.find('措施') != -1 or sentence.find('预防措施') != -1 or sentence.find('方法') != -1 or sentence.find('预防方法') != -1 or sentence.find('防汛') != -1:
            if sentence.find('学校') != -1 or sentence.find('大学') != -1 or sentence.find('本科') != -1 or sentence.find('高中') != -1 or sentence.find('初中') != -1 or sentence.find('小学') != -1 or sentence.find('小学') != -1 or sentence.find('幼儿园') != -1:
                ret = graph.run('MATCH p=(n:`橙色预警`{name:"暴雨橙色预警"})-[*]->(m:`学校`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('政府') != -1:
                ret = graph.run('MATCH p=(n:`橙色预警`{name:"暴雨橙色预警"})-[*]->(m:`政府`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('户外人员') != -1 or sentence.find('户外工作者') != -1:
                ret = graph.run('MATCH p=(n:`橙色预警`{name:"暴雨橙色预警"})-[*]->(m:`户外人员`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('城管部门') != -1:
                ret = graph.run('MATCH p=(n:`橙色预警`{name:"暴雨橙色预警"})-[*]->(m:`城管部门`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            else:
                f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
                f1.write(sentence + '\n')
                print("保存成功")
                f1.close()
                answerStence = '抱歉,我还不会,真正学习中!'
                #print(answerStence)
        elif sentence.find('降雨量')!=-1 or sentence.find('雨量')!=-1:
            ret = graph.run('MATCH p=(n:`橙色预警`{name:"暴雨橙色预警"})-[*]->(m:`级别标准`) return m').data()
            nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
            nodes = json.loads(nodesStr)
            answerStence = nodes['name']
            print(answerStence)
        else:
            f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
            f1.write(sentence + '\n')
            print("保存成功")
            f1.close()
            answerStence = '抱歉,我还不会,真正学习中!'
            #print(answerStence)
    elif sentence.find('红色')!=-1:
        if sentence.find('措施') != -1 or sentence.find('预防措施') != -1 or sentence.find('方法') != -1 or sentence.find('预防方法') != -1 or sentence.find('防汛') != -1:
            if sentence.find('学校') != -1 or sentence.find('大学') != -1 or sentence.find('本科') != -1 or sentence.find('高中') != -1 or sentence.find('初中') != -1 or sentence.find('小学') != -1 or sentence.find('小学') != -1 or sentence.find('幼儿园') != -1:
                ret = graph.run('MATCH p=(n:`红色预警`{name:"暴雨红色预警"})-[*]->(m:`学校`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('政府') != -1:
                ret = graph.run('MATCH p=(n:`红色预警`{name:"暴雨红色预警"})-[*]->(m:`政府`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            elif sentence.find('城管部门') != -1:
                ret = graph.run('MATCH p=(n:`红色预警`{name:"暴雨红色预警"})-[*]->(m:`城管部门`) return m').data()
                nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
                nodes = json.loads(nodesStr)
                answerStence = nodes['content']
                print(answerStence)
            else:
                f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
                f1.write(sentence + '\n')
                print("保存成功")
                f1.close()
                answerStence = '抱歉,我还不会,真正学习中!'
                #print(answerStence)
        elif sentence.find('降雨量')!=-1 or sentence.find('雨量')!=-1:
            ret = graph.run('MATCH p=(n:`红色预警`{name:"暴雨红色预警"})-[*]->(m:`级别标准`) return m').data()
            nodesStr = json.dumps(ret[0]['m'], ensure_ascii=False)
            nodes = json.loads(nodesStr)
            answerStence = nodes['name']
            print(answerStence)
        else:
            f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
            f1.write(sentence + '\n')
            print("保存成功")
            f1.close()
            answerStence = '抱歉,我还不会,真正学习中!'
            #print(answerStence)
    else:
        f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
        f1.write(sentence + '\n')
        print("保存成功")
        f1.close()
        answerStence = '抱歉,我还不会,真正学习中!'
else:
    f1 = open(r'/问题保存.txt', "a+", encoding='utf-8')
    f1.write(sentence + '\n')
    print("保存成功")
    f1.close()
    answerStence = '抱歉,我还不会,真正学习中!'
print(answerStence)

res_str=answerStence
synth_context=client.synthesis(res_str,'zh',1,{
    'spd':4,
    'vol': 5,
    'pit':9,
    'per':4})
with open("synth.mp3","wb")as f:
    f.write(synth_context)
playmp3.play_mp3("synth.mp3")

效果视频和github代码如下:

气象语音问答

代码如下:https://github.com/zhichen-roger/QAweather.git

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

经常喝假酒的胡小臣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值