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

泉州免费建站模板域名申请的方法

泉州免费建站模板,域名申请的方法,服务平台型网站,梅州市做试块网站德米特里祖布☀️ 一、介绍 正如您从标题中看到的#xff0c;这是一个演示项目#xff0c;显示了一个非常基本的语音助手脚本#xff0c;可以根据 Google 搜索结果在终端中回答您的问题。 您可以在 GitHub 存储库中找到完整代码#xff1a;dimitryzub/serpapi-demo-project… 德米特里·祖布☀️ 一、介绍 正如您从标题中看到的这是一个演示项目显示了一个非常基本的语音助手脚本可以根据 Google 搜索结果在终端中回答您的问题。 您可以在 GitHub 存储库中找到完整代码dimitryzub/serpapi-demo-projects/speech-recognition/cli-based/ 后续博客文章将涉及 使用Flask、一些 HTML、CSS 和 Javascript 的基于 Web 的解决方案。使用Flutter和Dart的基于 Android 和 Windows 的解决方案。 二、我们将在这篇博文中构建什么 2.1 环境准备 首先让我们确保我们处于不同的环境中并正确安装项目所需的库。最难可能是 安装 .pyaudio关于此种困难可以参看下文克服 [解决]修复 win 32/64 位操作系统上的 PyAudio pip 安装错误  2.2 虚拟环境和库安装 在开始安装库之前我们需要为此项目创建并激活一个新环境 # if youre on Linux based systems $ python -m venv env source env/bin/activate $ (env) path# if youre on Windows and using Bash terminal $ python -m venv env source env/Scripts/activate $ (env) path# if youre on Windows and using CMD python -m venv env .\env\Scripts\activate $ (env) path 解释python -m venv env告诉 Python 运行 module( -m)venv并创建一个名为 的文件夹env。代表“与”。source venv_name/bin/activate将激活您的环境并且您将只能在该环境中安装库。 现在安装所有需要的库 pip install rich pyttsx3 SpeechRecognition google-search-results 现在到pyaudio. 请记住pyaudio安装时可能会引发错误。您可能需要进行额外的研究。 如果您使用的是 Linux我们需要安装一些开发依赖项才能使用pyaudio $ sudo apt-get install -y libasound-dev portaudio19-dev $ pip install pyaudio 如果您使用的是 Windows则更简单使用 CMD 和 Git Bash 进行测试 pip install pyaudio 三、完整代码 import os import speech_recognition import pyttsx3 from serpapi import GoogleSearch from rich.console import Console from dotenv import load_dotenvload_dotenv(.env) console Console()def main():console.rule([bold yellow]SerpApi Voice Assistant Demo Project)recognizer speech_recognition.Recognizer()while True:with console.status(statusListening you..., spinnerpoint) as progress_bar:try:with speech_recognition.Microphone() as mic:recognizer.adjust_for_ambient_noise(mic, duration0.1)audio recognizer.listen(mic)text recognizer.recognize_google(audio_dataaudio).lower()console.print(f[bold]Recognized text[/bold]: {text})progress_bar.update(statusLooking for answers..., spinnerline)params {api_key: os.getenv(API_KEY),device: desktop,engine: google,q: text,google_domain: google.com,gl: us,hl: en}search GoogleSearch(params)results search.get_dict()try:if answer_box in results:try:primary_answer results[answer_box][answer]except:primary_answer results[answer_box][result]console.print(f[bold]The answer is[/bold]: {primary_answer})elif knowledge_graph in results:secondary_answer results[knowledge_graph][description]console.print(f[bold]The answer is[/bold]: {secondary_answer})else:tertiary_answer results[answer_box][list]console.print(f[bold]The answer is[/bold]: {tertiary_answer})progress_bar.stop() # if answered is success - stop progress bar.user_promnt_to_contiune_if_answer_is_success input(Would you like to to search for something again? (y/n) )if user_promnt_to_contiune_if_answer_is_success y:recognizer speech_recognition.Recognizer()continue # run speech recognizion again until user_promt nelse:console.rule([bold yellow]Thank you for cheking SerpApi Voice Assistant Demo Project)breakexcept KeyError:progress_bar.stop()error_user_promt input(Sorry, didnt found the answer. Would you like to rephrase it? (y/n) )if error_user_promt y:recognizer speech_recognition.Recognizer()continue # run speech recognizion again until user_promt nelse:console.rule([bold yellow]Thank you for cheking SerpApi Voice Assistant Demo Project)breakexcept speech_recognition.UnknownValueError:progress_bar.stop()user_promt_to_continue input(Sorry, not quite understood you. Could say it again? (y/n) )if user_promt_to_continue y:recognizer speech_recognition.Recognizer()continue # run speech recognizion again until user_promt nelse:progress_bar.stop()console.rule([bold yellow]Thank you for cheking SerpApi Voice Assistant Demo Project)breakif __name__ __main__:main() 四、代码说明 导入库 import os import speech_recognition import pyttsx3 from serpapi import GoogleSearch from rich.console import Console from dotenv import load_dotenv rich用于在终端中进行漂亮格式化的 Python 库。pyttsx3Python 的文本到语音转换器可离线工作。SpeechRecognition用于将语音转换为文本的 Python 库。google-search-resultsSerpApi 的 Python API 包装器可解析来自 15 个以上搜索引擎的数据。os读取秘密环境变量。在本例中它是 SerpApi API 密钥。dotenv从文件加载环境变量SerpApi API 密钥.env。.env文件可以重命名为任何文件.napoleon .点代表环境变量文件。 定义rich Console(). 它将用于美化终端输出动画等 console Console() 定义main所有发生的函数 def main():console.rule([bold yellow]SerpApi Voice Assistant Demo Project)recognizer speech_recognition.Recognizer() 在函数的开头我们定义speech_recognition.Recognizer()并将console.rule创建以下输出 ───────────────────────────────────── SerpApi Voice Assistant Demo Project ───────────────────────────────────── 下一步是创建一个 while 循环该循环将不断监听麦克风输入以识别语音 while True:with console.status(statusListening you..., spinnerpoint) as progress_bar:try:with speech_recognition.Microphone() as mic:recognizer.adjust_for_ambient_noise(mic, duration0.1)audio recognizer.listen(mic)text recognizer.recognize_google(audio_dataaudio).lower()console.print(f[bold]Recognized text[/bold]: {text}) console.status-rich进度条仅用于装饰目的。speech_recognition.Microphone()开始从麦克风拾取输入。recognizer.adjust_for_ambient_noise旨在根据环境能量水平校准能量阈值。recognizer.listen监听实际的用户文本。recognizer.recognize_google使用 Google Speech Recongition API 执行语音识别。lower()是降低识别文本。console.print允许使用文本修改的语句rich print例如添加粗体、斜体等。 spinnerpoint将产生以下输出使用python -m rich.spinner查看列表spinners 之后我们需要初始化 SerpApi 搜索参数以进行搜索 progress_bar.update(statusLooking for answers..., spinnerline) params {api_key: os.getenv(API_KEY), # serpapi api key device: desktop, # device used for engine: google, # serpapi parsing engine: https://serpapi.com/statusq: text, # search query google_domain: google.com, # google domain: https://serpapi.com/google-domainsgl: us, # country of the search: https://serpapi.com/google-countrieshl: en # language of the search: https://serpapi.com/google-languages# other parameters such as locations: https://serpapi.com/locations-api } search GoogleSearch(params) # where data extraction happens on the SerpApi backend results search.get_dict() # JSON - Python dict progress_bar.update将会progress_bar用新的status控制台中打印的文本进行更新spinnerline并将产生以下动画 之后使用 SerpApi 的Google 搜索引擎 API从 Google 搜索中提取数据。 代码的以下部分将执行以下操作 try:if answer_box in results:try:primary_answer results[answer_box][answer]except:primary_answer results[answer_box][result]console.print(f[bold]The answer is[/bold]: {primary_answer})elif knowledge_graph in results:secondary_answer results[knowledge_graph][description]console.print(f[bold]The answer is[/bold]: {secondary_answer})else:tertiary_answer results[answer_box][list]console.print(f[bold]The answer is[/bold]: {tertiary_answer})progress_bar.stop() # if answered is success - stop progress baruser_promnt_to_contiune_if_answer_is_success input(Would you like to to search for something again? (y/n) )if user_promnt_to_contiune_if_answer_is_success y:recognizer speech_recognition.Recognizer()continue # run speech recognizion again until user_promt nelse:console.rule([bold yellow]Thank you for cheking SerpApi Voice Assistant Demo Project)breakexcept KeyError:progress_bar.stop() # if didnt found the answer - stop progress barerror_user_promt input(Sorry, didnt found the answer. Would you like to rephrase it? (y/n) )if error_user_promt y:recognizer speech_recognition.Recognizer()continue # run speech recognizion again until user_promt nelse:console.rule([bold yellow]Thank you for cheking SerpApi Voice Assistant Demo Project)break 最后一步是处理麦克风没有拾取声音时的错误 # while True: # with console.status(statusListening you..., spinnerpoint) as progress_bar: # try:# speech recognition code# data extraction codeexcept speech_recognition.UnknownValueError:progress_bar.stop() # if didnt heard the speech - stop progress baruser_promt_to_continue input(Sorry, not quite understood you. Could say it again? (y/n) )if user_promt_to_continue y:recognizer speech_recognition.Recognizer()continue # run speech recognizion again until user_promt nelse:progress_bar.stop() # if want to quit - stop progress barconsole.rule([bold yellow]Thank you for cheking SerpApi Voice Assistant Demo Project)break console.rule()将提供以下输出 ───────────────────── Thank you for cheking SerpApi Voice Assistant Demo Project ────────────────────── 添加if __name__ __main__惯用语以防止用户在无意时意外调用某些脚本并调用main将运行整个脚本的函数 if __name__ __main__:main() 五、链接 richpyttsx3SpeechRecognitiongoogle-search-resultsosdotenv
http://www.sadfv.cn/news/228915/

相关文章:

  • 深圳网站建设注册长沙的企业网站建设
  • 做网站推广优化哪家好地矿局网站建设方案
  • 如何用源代码做网站搭建网站工具
  • 普法网站建设进入网络管理的网站
  • 制作网站的花多少钱怎么免费下wordpress
  • 宁波网站设计公司排名百度竞价排名魏则西事件分析
  • 网站设计报价表市场营销推广方案模板
  • 网站建设备案是什么意思怎样做网站建设
  • 汉口北做网站用手机做诱导网站
  • 营销型网站建站教程拓者吧室内设计网站
  • 喀什住房和城乡建设局网站口碑好的网站建设价格
  • 小清新网站源码互联网服务商
  • 单页销售网站模板广告公司做网站
  • 网站推广注意事项wordpress 绑定二级域名
  • 电子商务网站的建设流程是怎样的推广信息哪个平台好
  • 网站查询功能是用什么程序做的电子商务公司开发网站
  • 微网站开发项目合作协议梅西网页设计作业
  • 做网站电脑开一天用多少钱关键词seo资源
  • 法治网站的建设整改措施好的设计公司网站
  • 模板网站 优帮云在哪个网站做引号流最好
  • 网站开发简直wordpress 农场模板
  • Wordpress回复邮件通知国内seo公司排行榜前十名
  • 如何做网络营销推广服务机构新网站应该怎么做seo
  • 松江品划做企业网站网站关键词优化外包服务
  • 网站建设中的图片及视频要求代做关键词收录排名
  • 网站用表格做的吗网站服务器维护费用
  • 做字典网站开发购物网站用那个软件做
  • 建工行业建设标准网站做网站服务器怎么用
  • 师范街网站建设网推网站
  • 郑州有哪些搞网站开发的公司手机软件下载网站源码