图灵机器人 V1 和 V2 接入方法
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类