java无法调用音频设备_PyAudio无法捕获正确的音频数据

我无法获得PyAudio流来从USB麦克风中捕获音频数据 .

我在Ubuntu trusty(Ubuntu 14.04.3 LTS)上运行Python程序 . 我已将ALSA配置为将我的USB麦克风设置为默认声卡,并通过运行以下方式测试此工作是否正常:

arecord -D plughw:0,0 -f cd test.wav

然后使用播放该音频

aplay -D plughw:0,0 test.wav

My /etc/modprobe.d/alsa-base.conf file looks like this:

# autoloader aliases

install sound-slot-0 /sbin/modprobe snd-card-0

install sound-slot-1 /sbin/modprobe snd-card-1

install sound-slot-2 /sbin/modprobe snd-card-2

install sound-slot-3 /sbin/modprobe snd-card-3

install sound-slot-4 /sbin/modprobe snd-card-4

install sound-slot-5 /sbin/modprobe snd-card-5

install sound-slot-6 /sbin/modprobe snd-card-6

install sound-slot-7 /sbin/modprobe snd-card-7

# Cause optional modules to be loaded above generic modules

install snd /sbin/modprobe --ignore-install snd $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-ioctl32 ; /sbin/modprobe --quiet --use-blacklist snd-seq ; }

#

# Workaround at bug #499695 (reverted in Ubuntu see LP #319505)

install snd-pcm /sbin/modprobe --ignore-install snd-pcm $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-pcm-oss ; : ; }

install snd-mixer /sbin/modprobe --ignore-install snd-mixer $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-mixer-oss ; : ; }

install snd-seq /sbin/modprobe --ignore-install snd-seq $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-seq-midi ; /sbin/modprobe --quiet --use-blacklist snd-seq-oss ; : ; }

#

install snd-rawmidi /sbin/modprobe --ignore-install snd-rawmidi $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-seq-midi ; : ; }

# Cause optional modules to be loaded above sound card driver modules

install snd-emu10k1 /sbin/modprobe --ignore-install snd-emu10k1 $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-emu10k1-synth ; }

install snd-via82xx /sbin/modprobe --ignore-install snd-via82xx $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-seq ; }

# Load saa7134-alsa instead of saa7134 (which gets dragged in by it anyway)

install saa7134 /sbin/modprobe --ignore-install saa7134 $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist saa7134-alsa ; : ; }

# Prevent abnormal drivers from grabbing index 0

options bt87x index=-2

options cx88_alsa index=-2

options saa7134-alsa index=-2

options snd-atiixp-modem index=-2

options snd-intel8x0m index=-2

options snd-via82xx-modem index=-2

# options snd-usb-audio index=-2

options snd-usb-audio index=0

options snd-usb-caiaq index=-2

options snd-usb-ua101 index=-2

options snd-usb-us122l index=-2

options snd-usb-usx2y index=-2

# Ubuntu #62691, enable MPU for snd-cmipci

options snd-cmipci mpu_port=0x330 fm_port=0x388

# Keep snd-pcsp from being loaded as first soundcard

options snd-pcsp index=-2

我've installed PyAudio successfully, however when I open a stream, I don' t获取任何音频数据 . 我的理解是在使用PyAudio打开流时使用默认设备(除非 input_device_index 参数另有指定,我没有设置) .

p = pyaudio.PyAudio()

stream = p.open(

format=pyaudio.paInt16,

channels=1,

rate=18000,

input=True,

frames_per_buffer=1024

)

当我运行 PyAudio().get_device_info_by_index(0) 时,我得到:

{'defaultSampleRate': 16000.0, 'defaultLowOutputLatency': 0.0239375, 'defaultLowInputLatency': 0.0239375, 'maxInputChannels': 1L, 'structVersion': 2L, 'hostApi': 0L, 'index': 0, 'defaultHighOutputLatency': 0.096, 'maxOutputChannels': 2L, 'name': u'Jabra SPEAK 410 USB: Audio (hw:0,0)', 'defaultHighInputLatency': 0.096}

^(Jabra SPEAK 410 USB:音频)是我的USB麦克风 .

这些是PyAudio在加载时(在流被打开之前)吐出的日志 . 不过,我在网上看过,我可以忽略大部分错误 .

ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear

ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe

ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side

ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'

ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:4727:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM hdmi

ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'

ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:4727:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM hdmi

ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.modem.0:CARD=0'

ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:4727:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline:CARD=0,DEV=0

ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.modem.0:CARD=0'

ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:4727:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline:CARD=0,DEV=0

ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.modem.0:CARD=0'

ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:4727:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM phoneline

ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.modem.0:CARD=0'

ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:4727:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM phoneline

bt_audio_service_open: connect() failed: Connection refused (111)

bt_audio_service_open: connect() failed: Connection refused (111)

bt_audio_service_open: connect() failed: Connection refused (111)

bt_audio_service_open: connect() failed: Connection refused (111)

Cannot connect to server socket err = No such file or directory

Cannot connect to server request channel

jack server is not running or cannot be started

它看起来像流在打开时收集数据,但它没有捕获任何声音 . 我的麦克风打开,取消静音,并设置为捕获86级别的音频 .

我正在考虑默认设备没有正确设置(使用ALSA),因为当我这样做时:

arecord test.wav

aplay test.wav

没有记录 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是简单实用java调用WSDL接口,并解析返回数据格式的步骤: 1. 打开Eclipse,新建一个Java项目(例如:WsdlDemo)。 2. 在该项目下新建一个包(例如:com.demo),并在该包下新建一个类(例如:WsdlClient)。 3. 在该类加入以下代码: ```java package com.demo; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; public class WsdlClient { public static void main(String[] args) throws Exception { URL url = new URL("http://localhost:8080/HelloService?wsdl"); // WSDL文档地址 QName qname = new QName("http://demo.com/", "HelloServiceImplService"); // 服务名称和命名空间 Service service = Service.create(url, qname); HelloService hello = service.getPort(HelloService.class); // 获取服务实现类 String result = hello.sayHello("world"); // 调用服务方法 System.out.println(result); // 输出服务结果 } } ``` 4. 在该类同一级目录下新建一个接口(例如:HelloService),并在该接口定义要调用的服务方法: ```java package com.demo; import javax.jws.WebMethod; import javax.jws.WebService; @WebService public interface HelloService { @WebMethod String sayHello(String name); } ``` 5. 在Eclipse右键单击项目,选择Build Path -> Configure Build Path,在弹出的窗口选择Libraries标签页,然后点击Add External JARs按钮,选择从本地下载的JAX-WS相关jar包(例如:jaxws-api.jar、jaxb-api.jar),并点击OK按钮,将这些jar包添加到项目。 6. 运行该程序,可以看到输出了从服务端返回的结果。 至此,简单实用java调用WSDL接口,并解析返回数据格式的步骤就完成了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值