API1.0使用方法:

import requests
import json
import yuyinhecheng as hc def Tuling(words):
    Tuling_API_KEY = "你的AK"     body = {"key":Tuling_API_KEY,"info":words.encode("utf-8")}     url = "http://www.tuling123.com/openapi/api"
    r = requests.post(url,data=body)
    if r:
        date = json.loads(r.text)
        print (list(date))
        print(date['text'])
        hc.speak(date['text'])
        try:
            for mylist in date['list']:
                str2=mylist[list(mylist)[0]]
                print(str2)
                hc.speak(str2)
                print(mylist)
        except:
            pass
        return date["text"]
    else:
        return None if __name__=='__main__':
    Tuling('红烧肉菜谱')

API2.0使用方法:

import json
import urllib.request
import yuyinhecheng as hc def Tuling(text_input):
    api_url = "http://openapi.tuling123.com/openapi/api/v2"     req = {
        "perception":
    {
        "inputText":
        {
            "text": text_input
        },         "selfInfo":
        {
            "location":
            {
                "city": "天津",
                "province": "天津",
                "street": "中央大道"
            }
        }
    },     "userInfo":
    {
        "apiKey": "你的AK",
        "userId": "demo"
    }
    }
    # 将字典格式的req编码为utf8
    req = json.dumps(req).encode('utf8')     http_post = urllib.request.Request(api_url, data=req, headers={'content-type': 'application/json'})
    response = urllib.request.urlopen(http_post)
    response_str = response.read().decode('utf8')
    print(response_str)
    response_dic = json.loads(response_str)
    print(response_dic)     intent_code = response_dic['intent']['code']
    if (int(str(intent_code)[0])<4):
        print (str(intent_code))
        listp=list(response_dic['intent']['parameters'])
        print (response_dic['intent']['parameters'][listp[0]])
        str2=response_dic['results'][0]['values']['text']
        print(str2)
        hc.speak(str2)
        if ((intent_code==10003)or (intent_code==10015)) :
            for myresults in response_dic['results'][1]['values']['news']:
                print (myresults)
                print(myresults['name'])
                hc.speak(myresults['name'])
    else:
        print('错误。错误代码:' + str(intent_code)) if __name__=='__main__':
    Tuling('水煮鱼菜谱')

语言合成:


import win32com
import pyttsx3
def speak(str):
    engine = pyttsx3.init()
    voices = engine.getProperty('voices')
    engine.setProperty('voice',voices[3].id)
    engine.say(str)
    engine.runAndWait()

原文地址:https://blog.csdn.net/www_rsqdz_net/article/details/79680461

图灵机器人 V1 和 V2 接入方法的更多相关文章

  1. Python使用微信接入图灵机器人

    1.wxpy库介绍 wxpy 在 itchat 的基础上,通过大量接口优化提升了模块的易用性,并进行丰富的功能扩展. 文档地址:https://wxpy.readthedocs.io 从 PYPI 官 ...

  2. 【chrome插件】web版微信接入图灵机器人API实现自动回复

    小贱鸡自动回复API已经不可以用了,现在改良接入图灵机器人API 360chrome浏览器团队翻译了部分谷歌插件开发文档 地址:http://open.chrome.360.cn/extension_ ...

  3. Java接入图灵机器人,实现与机器人聊天

    很多人都玩过微信,其中就有与机器人聊天的功能:

  4. 不需要SDK调用图灵机器人的方法

    图灵机器人的调用其实就是你给服务器发一个文字消息过去,他回你一个,看起来模仿人类对话一样. 不知道为什么要弄个SDK这么麻烦的方法,以前的接口官网上已经没有了,但是还是可以用的.返回的是JSON但也懒 ...

  5. 个人微信接入图灵机器人(基于Python)

    编程语言:Python2.7 1.在图灵机器人官网(http://www.tuling123.com)注册账号, 创建机器人, 如果只是学习的话,可以使用2免费版 , 一个账号最多可以创建5个机器人 ...

  6. 图灵机器人api的使用方法含微信版本和网页版

    访问图灵机器人官网http://www.tuling123.com/ 注册一个新的机器人账号 注册成功后转到主页 点击我的机器人>创建机器人>微信机器人 填写基本信息 点击微信介入> ...

  7. python3+qqBot+图灵机器人实现qq聊天机器人

    原理: 通过Python3的qqBot开源库,基于腾讯的smartQQ协议登录个人QQ,实现监控.收集QQ消息,进而通过图灵机器人API接入方式实现自动聊天. 零.前期准备: 1.Python3 2. ...

  8. python 全栈开发,Day123(图灵机器人,web录音实现自动化交互问答)

    昨日内容回顾 . 百度ai开放平台 . AipSpeech技术,语言合成,语言识别 . Nlp技术,短文本相似度 . 实现一个简单的问答机器人 . 语言识别 ffmpeg (目前所有音乐,视频领域,这 ...

  9. 图灵机器人,web录音实现自动化交互问答

    一.图灵机器人 介绍 图灵机器人 是以语义技术为核心驱动力的人工智能公司,致力于“让机器理解世界”,产品服务包括机器人开放平台.机器人OS和场景方案. 官方地址为: http://www.tuling ...

随机推荐

  1. ORACLE SQL*PLUS 命令大全

    转至:https://www.cnblogs.com/kerrycode/archive/2011/06/09/2076248.html 其实网上已经有SQL*PLUS命令大全这方面的资料了,不过大都 ...

  2. 5个相见恨晚的Linux命令,每一个都非常实用

    转至:https://zhuanlan.zhihu.com/p/57866239 作为一个开发人员,经常要用到终端命令,最让人头疼的是记不住繁琐的参数.用谷哥度娘检索效率低下,通过man命令显示的结果 ...

  3. 《Symfony 5全面开发》教程05、http请求的query参数

    首先我们删除上节课所下的断点,在Phpstorm底部我们打开debug选项卡.点击这个按钮展开所有的PHP断点,选中之后点击这个删除,然后我们关闭xdebug监听. 回到浏览器刷新页面,当我们的浏览器 ...

  4. docker配置tomcat

    docker pull tomcat tomcat的目录结构 /usr/local/tomcat/webapps web目录 /usr/local/tomcat/logs 日志目录 /usr/loca ...

  5. Spark on Yarn出现hadoop.compression.lzo.LzoCodec not found问题发现及解决

    问题描述: spark.SparkContext: Created broadcast 0 from textFile at WordCount.scala:37 Exception in threa ...

  6. mapreduce类型对应

    public class OrderBean implements WritableComparable<OrderBean> { private Integer order_id; // ...

  7. kubernetes配置后端存储 rook-ceph

    一 Rook概述 1.1 Ceph简介 Ceph是一种高度可扩展的分布式存储解决方案,提供对象.文件和块存储.在每个存储节点上,将找到Ceph存储对象的文件系统和Ceph OSD(对象存储守护程序)进 ...

  8. Qt:QDateTime、QDate、QTime与QDateTimeEdit

    时间日期是经常遇到的数据类型,Qt中的时间日期类如下: QTime:时间类型,只表示时间,如15:23:13: QDate:日期类型,只表示日期,如2017-4-5: QDateTime:日期时间类型 ...

  9. Python:pandas(三)——DataFrame

    官方文档:pandas之DataFrame 1.构造函数 用法 pandas.DataFrame( data=None, index=None, columns=None, dtype=None, ) ...

  10. 在用Scrapy进行爬虫时碰到的错误

    1.module() takes at most 2 arguments (3 given) 解决方法:导入Spider类时,是from scrapy import Spider而不是from scr ...