即使 linux 中没有麦克风,声音输入也会出现声音输出

Sound output is present in sound input even with no mic in linux

我正在尝试同时播放声音和记录压电传感器的电压输出。为此,我将音板模拟输出连接到扬声器,将音板模拟输入连接到压电传感器。

当我记录来自传感器的信号但没有播放声音时,它工作得很好。但是,当我在录音过程中播放声音时,我可以在传感器的信号中看到我正在播放的声音,就好像音板的输出和输入是相连的。最奇怪的是,即使我拔掉传感器,录音中仍然存在输出信号。

换句话说,问题是:我开始录音,当我开始播放声音时,它出现在传感器的信号中(即使扬声器关闭)。

我只使用 ALSA,没有安装 pulseaudio。我正在使用 python(和 pyaudio)生成声音信号,将信号写入声卡输出并从声卡输入读取数据。我也在 Audacity 中测试过,但结果是一样的。我还测试了 arecord:

$ arecord --channel=1 --rate=128000 --format=S32_LE Test.wav

然后:

$ mplayer Audio/Alarms/Annoying_Alien_Buzzer-Kevan-1659966176.mp3 

然后停止录音。当我播放 Test.wav 时,播放文件的所有声音信号都在那里。

我知道这听起来很明显,但我想说的是设置中的任何地方都没有连接麦克风。

这是一些信息:

====================
盒子:

$ uname -a
Linux MalfattiTux 4.1.12-gentoo #3 SMP Thu Jan 21 17:24:27 BRST 2016 x86_64 Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz GenuineIntel GNU/Linux

音频板:

$ lspci | grep -i audio
00:03.0 Audio device: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor HD Audio Controller (rev 06)
00:1b.0 Audio device: Intel Corporation 8 Series/C220 Series Chipset High Definition Audio Controller (rev 05)## Heading ##

输出设备:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA Intel HDMI], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC3239 Analog [ALC3239 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 1: ALC3239 Digital [ALC3239 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

输入设备:

$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: PCH [HDA Intel PCH], device 0: ALC3239 Analog [ALC3239 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Python 播放和录制代码(最小工作示例):

import array
import pyaudio
import random

Rate = 128000
SoundPulseDur = 5 # in seconds

print('Generating sound pulse...')
SoundNoise = [random.random() for _ in range(round(Rate*SoundPulseDur))]
SoundPulse = [SoundNoise[ElI]*2-1 for ElI,ElV in enumerate(SoundNoise)]
SoundPulse[-1] = 0


print('Interleaving channels...')
SoundList = [0]*(2*len(SoundPulse))
for _ in range(len(SoundPulse)):
    SoundList[_ *2] = SoundPulse[_]
    SoundList[_ *2+1] = 0

Sound = array.array('f')
Sound.fromlist(SoundList)
Sound = bytes(Sound)


print('Generating sound objects...')
# Output
p = pyaudio.PyAudio()
Stimulation = p.open(format=pyaudio.paFloat32,
                channels=2,
                rate=Rate,
                output=True)

# Input
q = pyaudio.PyAudio()
InOn = False
RecStop = True
def InCallBack(in_data, frame_count, time_info, status):
    if InOn:
        global SoundRec
        SoundRec.append(in_data)

    if RecStop:
        InFlag = pyaudio.paComplete
    else:
        InFlag = pyaudio.paContinue
    return(None, InFlag)

Reading = q.open(format=pyaudio.paFloat32,
                     channels=1,
                     rate=Rate,
                     input=True,
                     output=False,
                     stream_callback=InCallBack)

SoundRec = []
Reading.start_stream()
RecStop = False; InOn = True
Stimulation.write(Sound)
InOn = False; RecStop = True
Reading.stop_stream()

这听起来像是来自您 sound-card 的电子噪音。我猜你用的是板载卡?如果是这样,除非您想购买 better/external sound-card.

,否则您无法避免录制噪音。

关于实际解决方案; 就个人而言,我会记录我的音频输出,并使用该音频数据来消除压电传感器数据中的噪音。

理论上这应该也可以在现场进行,如果您可以使用例如 PyAudio

将声音输出读取到压电录音脚本