当前位置: 首页 > news >正文

网站转载代码阿里巴巴怎么优化关键词排名

网站转载代码,阿里巴巴怎么优化关键词排名,网页设计与制作基础代码,免费博客平台强调:不用登录注册,直接使用就好 青云客智能聊天机器人API python代码,直接可以运行: 1、安装库: pip install requests pyttsx3 SpeechRecognition sounddevice numpy scipy2、完整代码: import request…

强调:不用登录注册,直接使用就好



青云客智能聊天机器人API

python代码,直接可以运行:
1、安装库:

pip install requests pyttsx3 SpeechRecognition sounddevice numpy scipy

2、完整代码:

import requests
import pyttsx3
import speech_recognition as sr
import sounddevice as sd
import numpy as np
import scipy.io.wavfile as wavfile
import tempfileclass ChatBot:def __init__(self, api_url, key="free", appid="0"):self.api_url = api_urlself.key = keyself.appid = appidself.tts_engine = pyttsx3.init()self.tts_engine.setProperty('rate', 150)  # 设置语速self.tts_engine.setProperty('volume', 1.0)  # 设置音量 (0.0到1.0)def send_message(self, message):params = {"key": self.key,"appid": self.appid,"msg": message}try:response = requests.get(self.api_url, params=params)response.raise_for_status()  # 检查请求是否成功data = response.json()if data.get("result") == 0:return data.get("content")else:return "对不起,我无法处理您的请求。"except requests.RequestException as e:return f"请求失败:{e}"def speak(self, text):self.tts_engine.say(text)self.tts_engine.runAndWait()def recognize_speech():# 设置录音参数sample_rate = 16000  # 采样率duration = 5  # 录音时长,秒print("请开始说话...")try:# 录制音频audio_data = sd.rec(int(sample_rate * duration), samplerate=sample_rate, channels=1, dtype='int16')sd.wait()  # 等待录音完成# 保存临时音频文件with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio:wavfile.write(temp_audio.name, sample_rate, audio_data)temp_audio_path = temp_audio.name# 使用 speech_recognition 进行语音识别recognizer = sr.Recognizer()with sr.AudioFile(temp_audio_path) as source:audio = recognizer.record(source)text = recognizer.recognize_google(audio, language="zh-CN")print(f"你: {text}")return textexcept sr.UnknownValueError:print("无法识别语音,请再试一次。")return Noneexcept sr.RequestError as e:print(f"语音识别服务出错: {e}")return Noneexcept Exception as e:print(f"录音出错: {e}")return Nonedef main():bot = ChatBot(api_url="http://api.qingyunke.com/api.php")print("欢迎使用语音聊天机器人!说“退出”结束对话。")bot.speak("欢迎使用语音聊天机器人,说退出结束对话。")while True:user_input = recognize_speech()if user_input is None:continueif "退出" in user_input:print("机器人: 再见!")bot.speak("再见!")breakresponse = bot.send_message(user_input)print(f"机器人: {response}")bot.speak(response)if __name__ == "__main__":main()

成功的同学,麻烦关注支持一下哦~~

http://www.dinnco.com/news/40092.html

相关文章:

  • 拟一份饰品网站建设合同设计网站
  • 长春网络公司做网站网址大全
  • 宁德住房和城乡建设部网站阿里seo排名优化软件
  • b2b平台网站毛片sem和seo哪个工作好
  • 大型网站建设兴田德润专业贵阳网站建设推广
  • 南宁营销型网站建设公司哪家好2023年6月疫情恢复
  • 做网站 带宽 多少钱怎么自己做一个网址
  • 织梦做淘宝客网站视频seo外链发布技巧
  • 淮安网站推广专业推广图片
  • 展示型网站包含哪些模块广东东莞最新情况
  • 安县网站制作电商网站公司
  • 怎么做网站认证网络营销岗位有哪些
  • 北太平庄做网站公司关键字有哪些
  • 市场监督管理局举报电话seo黑帽是什么
  • 佛山网站建设案例温州seo服务
  • 广东省住房和建设委员会网站网站建站设计
  • 网站优化一般要怎么做关键词分为哪三类
  • 注册公司那家网站做的比较好武汉新闻最新消息
  • 网站怎么做关键词研究项目推广平台有哪些
  • 河南艾特网站建设公司济南网络推广网络营销
  • 我要建网站毕业设计网站
  • 查询网站建设宁波 seo排名公司
  • 软件或网站是怎么做的百度手机点击排名工具
  • 网站要怎么做的海外游戏推广平台
  • 专业网站建设知识郑州网站排名推广
  • 做网站实例网络推广的方法有多选题
  • wordpress 下载文件插件优化设计答案四年级上册语文
  • 查询网站备案密码是什么情况百度高级搜索
  • wordpress默认居中seo网站诊断报告
  • 个人网站报价腾讯会议开始收费