我正在尝试制作一个可以录制音频并使用PyAudio,SpeechRecognition和PocketSphinx将其翻译成英文文本的Python应用程序.我正在运行Mac OS X El Capitan,版本10.11.2.
按照像这个和其他人的教程,我已经下载了PyAudio版本0.2.9,SpeechRecognition以及PocketSphinx.我已将它们安装到Conda环境中.我按照这个说明网站使用brew install swig git python
我的OS X,希望它能帮助.
这是我的代码:
# Load packages
import speech_recognition as sr
import sphinxbase
import pocketsphinx
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# write audio to a WAV file
with open("microphone-results.wav", "wb") as f:
f.write(audio.get_wav_data())
Run Code Online (Sandbox Code Playgroud)
到目前为止,事情进展顺利.我可以录制和播放我的WAV文件没问题.但这里出了问题......
r = sr.Recognizer()
with sr.AudioFile('microphone-results.wav') as source:
audio = r.record(source) # read the entire audio file
try:
print("You said …
Run Code Online (Sandbox Code Playgroud) python speech-recognition speech-to-text pyaudio pocketsphinx
我正在使用Flask Cookiecutter构建测试,并且所有其他测试都工作正常。仅当我测试使用元素的函数时才会出现问题g
,例如g.user
在 view.py 文件中。
我的conftest.py
与 Flask-cookiecutter 的完全相同,加上来自Flask-Testing 的伪造资源和上下文技巧的添加。
### conftest.py ###
...
from contextlib import contextmanager
from flask import appcontext_pushed, g
@contextmanager
def user_set(app, user):
def handler(sender, **kwargs):
g.user = user
with appcontext_pushed.connected_to(handler, app):
yield
...
Run Code Online (Sandbox Code Playgroud)
这是我的测试文件:
### test_file.py ###
from .conftest import user_set
import pytest
from my_app.utils import presave_posted_settings # <-- fn I want to test
@pytest.fixture()
def form_data():
return {...bunch of data..}
@pytest.mark.usefixtures("form_data")
class TestPresaveSettings:
"""Test cases for …
Run Code Online (Sandbox Code Playgroud)