- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
<分区>
我正在使用语音识别库创建类似 Siri 的程序。我希望将来我可以使用带有 Arduino 的代码来控制我房间周围的东西。这是我的问题:
我已经制定了基本的语音识别代码,但为了让程序理解某些命令,我必须通过一长串 if-elif-elif-elif-else 命令来运行语音,这可能会很慢。由于大多数时候它会在 else 处产生,因为命令不会被识别,我需要一个更快的替代方案来替代一长串 if-elif-else 语句。我也在用tts引擎给你回话。
这是我目前的代码
import pyttsx
import time
engine = pyttsx.init()
voices = engine.getProperty("voices")
spch = "There is nothing for me to say"
userSaid = "NULL"
engine.setProperty("rate", 130)
engine.setProperty("voice", voices[0].id)
def speak():
engine.say(spch)
engine.runAndWait()
def command():
**IF STATEMENT HERE**
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
print("CaSPAR is calibrated")
audio = r.listen(source)
try:
userSaid = r.recognize_google(audio)
except sr.UnknownValueError:
spch = "Sorry, I did'nt hear that properly"
except sr.RequestError as e:
spch = "I cannot reach the speech recognition service"
speak()
print "Done"
我想压缩一些看起来像这样的湿代码: if slips[i] 0: ac.setBackgroundOpacity(wheel['slip'], 1) 请注意,least_bound_inde
我有 5 组请求的类别定义为 python 字典,例如: category1 = {'type1', 'type2', 'type3'} category2 = {'type4', 'type5'}
这个问题在这里已经有了答案: Why does "a == x or y or z" always evaluate to True? How can I compare "a" to all of
我在网站上使用 Django,需要构建一个上下文处理器来提供引荐来源网址(名为 referer 的变量)信息。 我有一个简单的 if、elif、elif、else 语句: [ . . . ] host
这是我的个人项目,现在我的程序是大量 if 语句,这些语句基于我制作的字典,其中包含每一季的剧集编号(不同的季节有不同的剧集数)和标题。我得到了想要的结果,但是我一直在尝试寻找一种更高级的方法,例如使
在类方法中,我有一组针对单个关键字参数的可能选项,每个选项都有不同的算法来计算某些内容。为了检查哪个选项已添加到关键字中,我创建了一系列 if、elif、else 也找到了提供的关键字选项。 clas
所以我试图在 bash 脚本中执行 if else if else 语句。截至目前,当我运行此脚本时,我收到以下错误消息“./groupJobs.sh: line 76: syntax error n
我有一个 in if-elif-elif-else 语句,其中 99% 的时间执行 else 语句: if something == 'this': doThis() elif somethi
如果这是一个非常简单的问题,请原谅我。我已经在这几个小时了。我正在尝试每行读取一个 csv 文件。但是在最后一行,我不希望它附加任何“,”,这就是为什么我在 if-elif 语句中将问题分开。 我不确
税收计算器 def computeTax(maritalStatus,userIncome): if maritalStatus == "Single": print("User is s
我正在编写一个函数来清理字典数据,其中包含一个显示日期和该日期降雨量的键值对。数据清洗的条件是去除满足以下条件的和键值对: 类型不是整数或 float 。即使值是一个可以转换为整数的字符串(例如"5"
我正在编写一个函数来清理字典数据,其中包含一个显示日期和该日期降雨量的键值对。数据清洗的条件是去除满足以下条件的和键值对: 类型不是整数或 float 。即使值是一个可以转换为整数的字符串(例如"5"
这里有一些代码由于不正确的语句而不起作用 #Calculator print("This is a program that can be used as a calculator") print("
我想知道是否有更好的写法。下面所述的当前代码有效。我只是想知道是否有更好的方法。 这是为了验证。因此,if 语句检查所有必填字段,如果它们可以接受,则它会进入执行代码。问题开始是因为 的输入字段 se
我正在尝试使用 if elif 测试一个条件,但我没有得到想要的结果。请帮助我确定我做错了什么? #include using namespace std; #define a(t1)(t1+50)
#!/bin/bash if [ "$1" = "boot" ] then if [ -f /var/log/boot.log ] then echo /var/
./chkf: line 30: syntax error near unexpected token `elif' '/chkf: line 30: `elif [ -f "$object" ] ;
我想提取 Pandas 数据框中格式不一致的数据字段的位置。 (我不维护数据,因此无法更改此字段的格式。) 运行以下玩具版本 string2 = 'Denver.John' if string2.fi
亲们, 您将如何用字典重写“checkme”函数中的 if/elif? def dosomething(queue): ... def checkme(queue): """ Consum
我是 Python 的新手,我用它来做一个丑陋的小 put-this-tabular-data-into-a-db 转换。该程序查看数据,在 MySQL 中创建一个表,然后将数据读入表中。在本节中,将
我是一名优秀的程序员,十分优秀!