当前位置: 首页 > 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.dt0577.cn/news/53142.html

相关文章:

  • 网站建设shzanen公司营销网站建设
  • 卖文章的网站源码百度权重查询
  • 做三级分销网站设计app怎么推广运营
  • 做3d效果图的网站国外免费ip地址
  • dw5做简单的企业网站百度平台app
  • 深圳网站设计我选刻搜索关键词推荐
  • 博兴做网站推广排名seo
  • 网站制作苏州免费网站制作平台
  • 做挂网站推广普通话宣传语100字
  • 中小学网站建设规范广州百度关键词排名
  • 做电影网站的流程项目优化seo
  • 学生网上兼职网站搜索引擎优化的内容包括
  • 搭建自己的博客网站软件开发培训中心
  • 做暧小视频免费网站线上推广是什么工作
  • 做网站绘制蓝图的步骤免费有效的推广平台
  • 企业官方网站案例自己建网站需要多少钱
  • 有没有做奥数题的网站温州seo公司
  • 河南网络洛阳网站建设河南网站建设百度网页版浏览器
  • 怎么让wordpress泉州网站seo公司
  • 政府网站建设的工作总结网络营销总结及体会
  • 网站群建设路径线上营销手段有哪些
  • 哪些购物网站做的比较简洁有品质网站推广网络营销
  • 用宝塔做网站步骤网络营销是做什么的工作
  • 企业品牌网站建设价格windows优化大师要钱
  • 新公司简介模板范文googleseo排名公司
  • 购物网站开发教程 视频百度的人工客服电话
  • 五莲县财源建设网站无货源电商怎么做
  • 绿茵足球网站建设seo全网营销
  • 资源网站很难做引擎搜索
  • 2018网站开发最流行的语言中小企业网站优化