- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试制作一个使用语音识别的程序。现在我遇到了一个问题,这是你必须按下按钮或 Enter 才能开始语音识别。在 Python 3 中,有没有一种方法可以让您说出一个短语(有点像 Hey Google),它开始识别语音?
这是我的代码:
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
x = r.recognize_google(audio)
print("I'm listening!")
try:
print("You said: " + r.recognize_google(audio))
except speech_recognition.UnknownValueError:
print("I am sorry but I couldn't understand you, try again.")
except speech_recognition.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
提前致谢!
最佳答案
是的,基本上您必须将识别分为两部分:关键字识别(只听关键字)和主要识别(识别用户在关键字后说的话)。请注意,这意味着您的程序将始终处于监听状态。
对于关键字识别,您可以使用Recognizer()
的listen_in_background
方法并在您提供的任何回调中扫描关键字。如果找到关键字,则调用 Recognizer().listen(source)
。
由于收听关键字需要您的程序不断收听和识别,因此您不想使用任何需要互联网连接的语音识别 API(Bing、Google、Watson、Houndify 等...)。这是因为所有这些都有每月的 API 限制,您很容易就会用完这些限制。您想保存这些 API 以供实际识别。我相信您唯一的离线选择是使用 recognize_sphinx
或 snowboy 热词检测。我从来没有真正使用过 Snowboy(尽管我听说它非常好),因为它在 Windows 上不起作用(或者至少在我编写程序时它不起作用),但是 Sphinx 有一个关键字检测工具。
基本上,您传递 sphinx_recognizer 关键字以及它应该通过元组拾取这些关键字的敏感度,它会尝试专注于在语音中查找这些词。请注意,关键字越敏感,误报就越多。
这是一个例子:
import speech_recognition as sr
import time
r = sr.Recognizer()
# Words that sphinx should listen closely for. 0-1 is the sensitivity
# of the wake word.
keywords = [("google", 1), ("hey google", 1), ]
source = sr.Microphone()
def callback(recognizer, audio): # this is called from the background thread
try:
speech_as_text = recognizer.recognize_sphinx(audio, keyword_entries=keywords)
print(speech_as_text)
# Look for your "Ok Google" keyword in speech_as_text
if "google" in speech_as_text or "hey google":
recognize_main()
except sr.UnknownValueError:
print("Oops! Didn't catch that")
def recognize_main():
print("Recognizing Main...")
audio_data = r.listen(source)
# interpret the user's words however you normally interpret them
def start_recognizer():
r.listen_in_background(source, callback)
time.sleep(1000000)
start_recognizer()
此链接在使用 speech_recognition 库时非常有用:
https://github.com/Uberi/speech_recognition/blob/master/reference/library-reference.rst
关于python - 说了Python怎么开始录音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53691128/
我正在使用 twilio JS 客户端从 Web 进行调用。客户端调用后端获取 token 。这里是返回 token 的后端代码。如何记录通话。表示在哪里设置录制网址。通话成功。但是不知道从哪里传录音
我有一个软件,可以记录 5 秒间隔的声音,然后将其发送进行处理。它在无限循环中运行,如下所示: while (true) { System.out.println("recording..")
我目前正在做一个项目,需要录制 iPhone 播放的声音。通过这个,我的意思是录制在后台播放的声音,如声音剪辑或其他任何东西,而不是使用内置麦克风。 这能做到吗?我目前正在试验 AVAudioReco
当我将蓝牙免提连接到 Android 手机设备时,是否可以使用手机麦克风录制声音并在免提中听到? 我设法通过手机麦克风录制声音,并通过手机扬声器或耳机听到声音。但是当耳机有麦克风时,通常是免提,它默认
我想访问我在我的应用程序中记录的跟踪数据和自定义数据。 有人可以提供不同数据轨道保存在 mp4 中的格式吗? 使用这个例子https://github.com/google-ar/arcore-and
我想知道,在C++中进行音频记录/回放/搜索的跨平台实用工具是什么?我当时在考虑采用ALUT(OpenAL)的路线,但是有更好的方法吗?如果不是,你们是否知道ALUT的任何优秀教程/示例代码? 最佳答
我目前正在开发一个项目,该项目允许用户录制音频消息,但是最近提出了一个要求,允许他们暂停录制过程,然后继续录制(将新的音频追加到之前的录制之后)。 示例: 用户按下记录并进行初始记录。 用户按下暂停按
我见过几个这样的例子,但它们似乎是针对旧版本的 SDK。我正在尝试设置基本的录音,以下代码在针对 SDK 2.0 版时给我一个 NullPointerException。 ContentValues
我开发了一款安卓游戏,使用 Audio Record 获取麦克风输入。 可以看一下https://play.google.com/store/apps/details?id=fixappmedia.m
我想在最近的项目中使用该插件进行音频捕获。我找到了 Matt Diamond 的努力 demo here正如大多数文章所指向的那样。我尝试在本地重新创建这个完全相同的演示,但没有成功。 我包括了所有依
我正在设置录音机,但在 soundRecorder = try AVAudioRecorder(URL: getFileURL(), settings: recordSettings as! [Str
作为一名吉他手,我一直想开发自己的录音、混音软件。我在 Direct Sound、Windows Multimedia(waveOutOpen 等)方面有一些经验。我意识到这将是一个复杂的项目,但纯粹
我不想记录我自己的击键来创建 asciinema 教程,而是想编写它们的脚本,这样我就可以随着时间的推移轻松地改进我的教程,而不必担心每次我想进行更改时都要重做,或者花很多时间尝试更正录音中的错别字。
我正在尝试使用 Flutter 构建一个应用程序,其中包含录音机。如何访问录音机?请帮我弄清楚它的包、依赖项和代码。 最佳答案 您可以使用 audio_recorder 包: https://pub.
掌握 Java Flight recorder (JFR) 配置,我有一个最合理的配置: -XX:+UnlockCommercialFeatures -XX:+DebugNonSafepoints -
我正在尝试播放我从 twilio 取回的通话录音。到目前为止,我在我的网站上有一个所有通话录音的列表,当我点击它们时,它会将我发送到 twilio 以收听它们。然后我发出一个 ajax 请求以从 tw
我们可以用 iPhone 直接线路输入录制音频吗? 最佳答案 唯一的方法是使用底座连接器创建您自己的配件,然后使用提供的 API! 关于iPhone LINE-IN 录音 可以吗?,我们在Stack
基本上,我希望用户使用 SoundCloud 录音机录制声音,一旦他们单击“保存”,他们刚刚录制的声音就会嵌入到我的网页中。 我使用 SC.record() 方法来获取录音。这是我保存录音的功能...
我正在尝试在网站中实现录音。基本上,用户应该能够按下一个按钮并对着麦克风说些什么。然后应将录制的音频发送到服务器以进行进一步处理。我知道您可以使用 Flash 做到这一点,但现在我正在努力避免这种情况
我正在尝试“录制”一个音频文件,我读过这个 doc ,实际上我想在文件中将“采样”值记录为双倍值,这是我使用的代码(不起作用,我不知道为什么没有): /* Use the newer ALSA API
我是一名优秀的程序员,十分优秀!