- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
您好,我正在与 pyaudio 合作构建一个应用程序,该应用程序可以实时记录和播放音频,并向音频信号添加低通滤波器。当我尝试运行此代码时,出现以下错误:
Pyaudio:播放错误:4
from pyaudio import PyAudio, paContinue, paFloat32
from time import sleep
from numpy import array, random, arange, float32, float64, zeros
import sounddevice as sd
fs = 44100 # Hz
threshold = 0.8 # absolute gain
delay = 40 # samples
signal_length = 1 # second
release_coeff = 0.5555 # release time factor
attack_coeff = 0.5 # attack time factor
dtype = float32 # default data type
block_length = 1024 # samples
class Limiter:
def __init__(self, attack_coeff, release_coeff, delay, dtype=float32):
self.delay_index = 0
self.envelope = 0
self.gain = 1
self.delay = delay
self.delay_line = zeros(delay, dtype=dtype)
self.release_coeff = release_coeff
self.attack_coeff = attack_coeff
def limit(self, signal, threshold):
for i in arange(len(signal)):
self.delay_line[self.delay_index] = signal[i]
self.delay_index = (self.delay_index + 1) % self.delay
# calculate an envelope of the signal
self.envelope *= self.release_coeff
self.envelope = max(abs(signal[i]), self.envelope)
# have self.gain go towards a desired limiter gain
if self.envelope > threshold:
target_gain = (1+threshold-self.envelope)
else:
target_gain = 1.0
self.gain = ( self.gain*self.attack_coeff +
target_gain*(1-self.attack_coeff) )
# limit the delayed signal
signal[i] = self.delay_line[self.delay_index] * self.gain
print "Recording Audio"
signal = sd.rec(signal_length * fs, samplerate=fs, channels=1, dtype=dtype)
sd.wait()
print "Audio recording complete , Play Audio"
original_signal = array(signal, copy=True, dtype=dtype)
limiter = Limiter(attack_coeff, release_coeff, delay, dtype)
def callback(in_data, frame_count, time_info, flag):
if flag:
print("Playback Error: %i" % flag)
played_frames = callback.counter
callback.counter += frame_count
limiter.limit(signal[played_frames:callback.counter], threshold)
return signal[played_frames:callback.counter], paContinue
callback.counter = 0
pa = PyAudio()
stream = pa.open(format = paFloat32,
channels = 1,
rate = fs,
frames_per_buffer = block_length,
output = True,
stream_callback = callback)
while stream.is_active():
sleep(0.1)
stream.close()
pa.terminate()
最佳答案
您不应该混合使用 PyAudio 和 sounddevice
!
无论如何,函数sounddevice.rec()和 sounddevice.wait()如果在回调函数中调用它们将无法正常工作(因为它们在内部使用自己的“流”和自己的回调函数)。
关于python - pyaudio : Playback Error: 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36212277/
是否有可能在网站上添加音频文件,即使用户在页面之间导航,该音频文件仍会在整个网站中继续播放? 最佳答案 也许您可以为音频播放器打开一个新的单独窗口,或者使用iframe? http://www.bou
有没有一种方法可以使用DirectSound从头开始创建声音,例如演奏c,d,e,f,g等音符?但是,声音必须逼真的声音,并且至少听起来像适当的声音。 谢谢。我已尽我所能,尽量做到简洁明了。 最佳答案
我知道这是关于特定程序(mplayer 后端);然而它将用于前端编程,所以我希望它仍然被认为是 Stack Overflow 上的主题。 我想运行两个 mplayer 从实例,它们将用于在不同的音频流
我使用 TI 提供的工具链及其 SDK 6.00.00 为 TI AM335x 板交叉编译了 Qt 5.2.1。 不幸的是,我无法在 QML 中重现任何视频... 调试控制台告诉我们: default
我需要创建一个文本区域,用户可以在其中键入文本,管理员应该能够以不同的速度播放用户的操作。 例如:用户输入 - 我的名字是 Bob 并输入 Dave,我需要捕获这些,以便当管理员“回放”时,他应该看到
尝试在 xcode 10.1 中构建木琴时,在 iOS12 上使用 swift 4.2,我使用按钮播放 .wav 文件并输入以下代码,但出现以下错误: "type 'String' has no me
您好,我正在与 pyaudio 合作构建一个应用程序,该应用程序可以实时记录和播放音频,并向音频信号添加低通滤波器。当我尝试运行此代码时,出现以下错误: Pyaudio:播放错误:4 from pya
我有两个不同的 PCM 样本流。是否有可能以某种方式混合它们并在同一输出设备上与 ALSA 一起使用? 我读到使用混音器可能是可能的,但由于缺乏文档,我发现很难理解。任何人都可以提供一些有关如何实现的
我目前正在研究音频可视化,并尝试使用 Spotify 的 Web Playback SDK 直接在我的网站上播放和分析歌曲。 但是,我不确定在实际读取流数据时有什么限制。我注意到为 Spotify 播
在我的 HTC Desire (Froyo) 中,我从一个安卓应用程序发起了一个调用,当调用结束时,我的安卓应用程序通过显示 进入待机模式 log cat 中“AudioHardware pcm pl
我已经搜索过,但仍然找不到答案。 我正在使用 API 21 中的 androids MediaCodec(使用解码器和表面)制作一个简单的视频播放器。但是,视频播放速度非常快。如何以正常速度播放视频?
在我的 iOS 应用程序中,我首先启动 iPod 中的歌曲,然后启动我的应用程序。我在我的应用程序中按下一个按钮,然后调用 AVAudioSession * audioSession = [AVAud
我想在 HTML5 中做这样的事情,我有这样的东西: 我希望能够做到这一点,当我点击“开始”按钮时,刻度标记逐渐移动到下一个刻度并每秒递增 1,点击“停止”停止行为,再次点击“开始”从当前位置。顶部的
我正在尝试开发一个小示例,我将在通用 Windows 应用程序中使用 MediaCapture 和 MediaPlayer 类来录制和播放一段简短的录音。 以下对构造函数的调用在 Visual Stu
我们在使用 cocoalibspotify 播放时出现崩溃:问题看起来像在 SPSession.m 下的回调函数 music_delivery() 中,实例启动的回调不是 SPSessionAudio
我收到错误消息“该视频包含来自UMG的内容。在某些站点上不能播放。”尝试在Chrome扩展程序中播放某些嵌入式YouTube视频时。 我正在使用YouTube IFrame API。 所有代码都在弹出
我正在使用python开发一个SIP客户端,基于pjsua2 。我有一个基于 python wrapper call 的自定义调用类我的代码能够获得有效的连接。在我的自定义 onCallMediaSt
我目前有一个 MusicPlayer其中包含 MusicSequence带有一组 MusicTracks保存 MIDI 信息。我想要知道 MIDI Note 何时开始再现以及何时结束,就像 MIDI
我正在运行 5.1 的 Moto-E 上测试 Soundpool。它通常以极好的延迟开始 - 但随后音频开始挂起一百毫秒或更长时间,并显示以下消息: 06-26 15:03:49.213 3865-9
有没有人有使用Strobe Media Playback的经验? (OSMF) 在真实项目中? 它与 JW Player 和 Flowplayer 相比如何? 请接受任何答案。 谢谢! 最佳答案 OS
我是一名优秀的程序员,十分优秀!