标签: pyaudio

属性错误:找不到 PyAudio;检查安装...无法使用语音识别

我正在尝试制作一个基本的语音识别助手。当我运行代码时,它告诉我:

Traceback (most recent call last):
  File "C:\Users\Mo.haytham\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 108, in get_pyaudio
    import pyaudio
ModuleNotFoundError: No module named 'pyaudio'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Mo.haytham/.PyCharmCE2018.3/config/scratches/ALPHA_BASIC.py", line 22, in <module>
    hear()
  File "C:/Users/Mo.haytham/.PyCharmCE2018.3/config/scratches/ALPHA_BASIC.py", line 13, in hear
    with sr.Microphone() as sourse:
  File "C:\Users\Mo.haytham\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__
    self.pyaudio_module = self.get_pyaudio()
  File "C:\Users\Mo.haytham\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 110, in get_pyaudio
    raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation 
Run Code Online (Sandbox Code Playgroud)

我尝试过, …

python visual-c++ pyaudio python-3.x

11
推荐指数
3
解决办法
3万
查看次数

在设置PyAudio Stream输入和输出为True时获取IOError:[Errno输入溢出] -9981

我正在尝试在我的Mac(OS 10.7.2)上运行以下代码(来自PyAudio文档的示例):

import pyaudio
import sys

chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5

p = pyaudio.PyAudio()

stream = p.open(format = FORMAT,
                channels = CHANNELS,
                rate = RATE,
                input = True,
                output = True,
                frames_per_buffer = chunk)

print "* recording"
for i in range(0, 44100 / chunk * RECORD_SECONDS):
    data = stream.read(chunk)
    stream.write(data, chunk)
print "* done"

stream.stop_stream()
stream.close()
p.terminate()
Run Code Online (Sandbox Code Playgroud)

我给出的错误是:

Traceback (most recent call last):
  File "PyAudioExample.py", line 24, in <module>
data …
Run Code Online (Sandbox Code Playgroud)

python portaudio pyaudio

10
推荐指数
1
解决办法
4483
查看次数

如何在Mac OS X 10.7上的virtualenv中安装PyAudio

我试过了

easy_install pyaudio
Run Code Online (Sandbox Code Playgroud)

它不起作用.我得到以下内容:

Searching for pyaudio
Reading http://pypi.python.org/simple/pyaudio/
Reading http://people.csail.mit.edu/hubert/pyaudio/
Best match: pyaudio 0.2.7
Downloading http://people.csail.mit.edu/hubert/pyaudio/packages/pyaudio-0.2.7.tar.gz
Processing pyaudio-0.2.7.tar.gz
Writing /var/folders/vg/98k5hfl52m16wm45ckdx1_5c0000gp/T/easy_install-s1wLkT/PyAudio-0.2.7/setup.cfg
Running PyAudio-0.2.7/setup.py -q bdist_egg --dist-dir /var/folders/vg/98k5hfl52m16wm45ckdx1_5c0000gp/T/easy_install-s1wLkT/PyAudio-0.2.7/egg-dist-tmp-pFDrFR
warning: no files found matching '*.c' under directory 'test'
clang: warning: argument unused during compilation: '-mno-fused-madd'
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
         ^
1 error generated.
error: Setup script exited with error: command 'clang' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)

python macos virtualenv pyaudio

10
推荐指数
2
解决办法
7048
查看次数

使用PyAudio录制扬声器输出

我正试图用PyAudio记录计算机扬声器的输出.我试图修改PyAudio文档中给出的代码示例,但它不起作用.这是我的代码:

import pyaudio
import wave

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"

p = pyaudio.PyAudio()

SPEAKERS = p.get_default_output_device_info()["hostApi"] #The part I have modified

stream = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                input=True,
                frames_per_buffer=CHUNK,
                input_host_api_specific_stream_info=SPEAKERS) #The part I have modified

print("* recording")

frames = []

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
    data = stream.read(CHUNK)
    frames.append(data)

print("* done recording")

stream.stop_stream()
stream.close()
p.terminate()

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close() …
Run Code Online (Sandbox Code Playgroud)

python pyaudio

10
推荐指数
4
解决办法
1万
查看次数

Python pocketsphinx RequestError:缺少PocketSphinx模块:确保正确设置PocketSphinx

我正在尝试制作一个可以录制音频并使用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

10
推荐指数
3
解决办法
1万
查看次数

无法在谷歌colab中安装pyaudio

当我尝试运行时pip install PyAudio,我看到以下错误:

  Using cached https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Building wheels for collected packages: PyAudio
  Building wheel for PyAudio (setup.py) ... error
  ERROR: Failed building wheel for PyAudio
  Running setup.py clean for PyAudio
Failed to build PyAudio
Installing collected packages: PyAudio
    Running setup.py install for PyAudio ... error
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-o_0h_bmo/PyAudio/setup.py'"'"'; __file__='"'"'/tmp/pip-install-o_0h_bmo/PyAudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-8_ovxdkm/install-record.txt --single-version-externally-managed --compile Check the logs for …
Run Code Online (Sandbox Code Playgroud)

python pyaudio google-colaboratory

10
推荐指数
1
解决办法
2万
查看次数

用Python录音

我想用Python录制USB麦克风的短音频片段.我已经尝试了pyaudio,它似乎无法与ALSA通信,而alsaaudio,其代码示例产生了一个不可读的文件.

所以我的问题是:在Python中用USB麦克风录制剪辑的最简单方法是什么?

python microphone alsa audio-recording pyaudio

9
推荐指数
1
解决办法
1万
查看次数

为Google Speech API创建合适的WAV文件

我正在使用pyaudio将我的声音录制为wav文件.我正在使用以下代码:

def voice_recorder():
    FORMAT = pyaudio.paInt16
    CHANNELS = 2
    RATE = 22050
    CHUNK = 1024
    RECORD_SECONDS = 4
    WAVE_OUTPUT_FILENAME = "first.wav"

    audio = pyaudio.PyAudio()

    # start Recording
    stream = audio.open(format=FORMAT, channels=CHANNELS,
                    rate=RATE, input=True,
                    frames_per_buffer=CHUNK)
    print "konusun..."
    frames = []

    for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
        data = stream.read(CHUNK)
        frames.append(data)
    #print "finished recording"


    # stop Recording
    stream.stop_stream()
    stream.close()
    audio.terminate()

    waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
    waveFile.setnchannels(CHANNELS)
    waveFile.setsampwidth(audio.get_sample_size(FORMAT))
    waveFile.setframerate(RATE)
    waveFile.writeframes(b''.join(frames))
    waveFile.close()
Run Code Online (Sandbox Code Playgroud)

我正在使用以下Google Speech API代码,它基本上将WAV文件中的语音转换为文本:https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/api-client/transcribe. PY

当我尝试将由pyaudio生成的wav文件导入Google的代码时,我收到以下错误:

googleapiclient.errors.HttpError: <HttpError …
Run Code Online (Sandbox Code Playgroud)

python wav pyaudio google-speech-api

9
推荐指数
1
解决办法
1853
查看次数

输出音频文件未正确创建,或者持续时间未知

我目前正在尝试记录一些话语,其中记录会话应该在按下并按下按键时开始,并在释放时停止.我制作了用于记录和存储数据的python脚本.

from pynput import keyboard
import time
import pyaudio
import wave

CHUNK = 8192
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"

p = pyaudio.PyAudio()
frames = []

def callback(in_data, frame_count, time_info, status):
    return (in_data, pyaudio.paContinue)

class MyListener(keyboard.Listener):
    def __init__(self):
        super(MyListener, self).__init__(self.on_press, self.on_release)
        self.key_pressed = None

        self.stream = p.open(format=FORMAT,
                             channels=CHANNELS,
                             rate=RATE,
                             input=True,
                             frames_per_buffer=CHUNK,
                             stream_callback = self.callback)
        print self.stream.is_active()

    def on_press(self, key):
        if key == keyboard.Key.cmd_l:
            self.key_pressed = True

    def on_release(self, key):
        if key …
Run Code Online (Sandbox Code Playgroud)

python keyboard-events pyaudio

9
推荐指数
1
解决办法
463
查看次数

Flask 将 pyaudio 发送到浏览器

我将服务器麦克风的音频发送到浏览器(大部分像这篇文章,但有一些修改的选项)。

一切都工作正常,直到你转到手机或野生动物园,它根本不起作用。我尝试过使用像howler这样的东西来处理前端,但没有成功(仍然可以在 Chrome 和计算机上使用,但不能在手机 Safari/Chrome/等上使用)。<audio> ... </audio>在 Chrome 中运行良好,但仅在计算机上运行。

function play_audio() {
  var sound = new Howl({
    src: ['audio_feed'],
    format: ['wav'],
    html5: true,
    autoplay: true
  });
  sound.play();
}
Run Code Online (Sandbox Code Playgroud)

如何发送可在任何浏览器中运行的“实时”wav 生成的音频源?

编辑230203:

我已将错误范围缩小到标题(至少我认为是导致错误的原因)。

应该使用什么标头才能使声音在所有浏览器中可用?

就拿这个简单的app.py例子来说:

from flask import Flask, Response, render_template
import pyaudio
import time

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html', headers={'Content-Type': 'text/html'})

def generate_wav_header(sampleRate, bitsPerSample, channels):
    datasize = 2000*10**6
    o = bytes("RIFF",'ascii')
    o += (datasize + 36).to_bytes(4,'little')
    o += bytes("WAVE",'ascii') …
Run Code Online (Sandbox Code Playgroud)

html python flask pyaudio

9
推荐指数
1
解决办法
1045
查看次数