- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
概述:这是我上一个问题 ( here ) 的后续问题。我将很快发布完整的答案。我可以让 pocketsphinx 通过 Gstreamer 在 Python 中识别来自 PS3 Eye 的音频输入。通过指定正确的 alsa 设备(在我的例子中为 hw:1 )。
问题:我的下一个问题似乎涉及一个微小的竞争条件,涉及我的麦克风已在使用中并且需要能够录制某些内容。
想象一下以下情况:
现在看来,当我开始第 3 步时,麦克风再次停止工作。我运行了一些详细的选项来尝试弄清楚发生了什么,但检查我的/tmp/目录告诉我一切:
pi@scarlettpi ~ $ ls -lta /tmp/ | grep wav
-rw-r--r-- 1 pi pi 0 Aug 13 20:57 fsdgjdspi.wav
pi@scarlettpi ~ $
文件大小为 0 字节。没有记录任何内容。
为了确认我通过 strace 运行了该过程并确认了我的怀疑:
pi@scarlettpi ~ $ strace -p 12416 | tee -a pi.strace.log 2>&1
Process 12416 attached - interrupt to quit
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, -1) = 1 ([{fd=3, revents=POLLIN}])
read(3, "\1\0\0\0\0\0\0\0", 16) = 8
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, -1) = 1 ([{fd=3, revents=POLLIN}])
read(3, "\1\0\0\0\0\0\0\0", 16) = 8
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, -1) = 1 ([{fd=3, revents=POLLIN}])
read(3, "\1\0\0\0\0\0\0\0", 16) = 8
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, -1) = 1 ([{fd=3, revents=POLLIN}])
read(3, "\1\0\0\0\0\0\0\0", 16) = 8
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, -1) = 1 ([{fd=3, revents=POLLIN}])
read(3, "\1\0\0\0\0\0\0\0", 16) = 8
ioctl(7, 0x80044121, 0xbebd764c) = 0
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
futex(0x1e47f34, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x1e47f30, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1
futex(0x1e45218, FUTEX_WAKE_PRIVATE, 1) = 1
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
ioctl(7, 0x80044121, 0xbebd764c) = 0
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
gettimeofday({1376379565, 54761}, NULL) = 0
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
open("/usr/local/lib/python2.7/dist-packages/pi-0.1.0-py2.7.egg/static/sounds/pi-listening.wav", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
open("/usr/local/lib/python2.7/dist-packages/pi-0.1.0-py2.7.egg/static/sounds/pi-listening.wav", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
lstat64("/tmp/tmpkTS2Fwpi.wav", 0xbebd73a0) = -1 ENOENT (No such file or directory)
socketpair(PF_FILE, SOCK_STREAM, 0, [19, 20]) = 0
fcntl64(19, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
fcntl64(20, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
brk(0x1f20000) = 0x1f20000
socketpair(PF_FILE, SOCK_STREAM, 0, [21, 22]) = 0
fcntl64(21, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
fcntl64(22, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
write(1, "Bossjones Note: Technically we'r"..., 97) = 97
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
stat64("/usr/share/alsa/alsa.conf", {st_mode=S_IFREG|0644, st_size=9184, ...}) = 0
open("/dev/snd/controlC1", O_RDONLY|O_CLOEXEC) = 23
fcntl64(23, F_SETFD, FD_CLOEXEC) = 0
ioctl(23, UI_DEV_CREATE, 0xbebd6dd4) = 0
close(23) = 0
open("/dev/snd/controlC1", O_RDWR|O_CLOEXEC) = 23
fcntl64(23, F_SETFD, FD_CLOEXEC) = 0
ioctl(23, USBDEVFS_CONTROL or USBDEVFS_CONTROL32, 0xbebd6f74) = 0
ioctl(23, 0x40045532, 0xbebd6fac) = 0
open("/dev/snd/pcmC1D0c", O_RDWR|O_NONBLOCK|O_CLOEXEC) = -1 EBUSY (Device or resource busy)
close(23) = 0
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
open("/tmp/tmpkTS2Fwpi.wav", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 23
fstat64(23, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f6f000
_llseek(23, 0, [0], SEEK_SET) = 0
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
stat64("/usr/share/alsa/alsa.conf", {st_mode=S_IFREG|0644, st_size=9184, ...}) = 0
open("/dev/snd/controlC1", O_RDONLY|O_CLOEXEC) = 24
fcntl64(24, F_SETFD, FD_CLOEXEC) = 0
ioctl(24, UI_DEV_CREATE, 0xbebd6dd4) = 0
close(24) = 0
open("/dev/snd/controlC1", O_RDWR|O_CLOEXEC) = 24
fcntl64(24, F_SETFD, FD_CLOEXEC) = 0
ioctl(24, USBDEVFS_CONTROL or USBDEVFS_CONTROL32, 0xbebd6f74) = 0
ioctl(24, 0x40045532, 0xbebd6fac) = 0
open("/dev/snd/pcmC1D0c", O_RDWR|O_NONBLOCK|O_CLOEXEC) = -1 EBUSY (Device or resource busy)
close(24) = 0
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(1, " * Listening closely...\n", 24) = 24
clock_gettime(CLOCK_MONOTONIC, {355220, 267713756}) = 0
clock_gettime(CLOCK_MONOTONIC, {355220, 268557726}) = 0
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 1 ([{fd=3, revents=POLLIN}])
read(3, "-\0\0\0\0\0\0\0", 16) = 8
clock_gettime(CLOCK_MONOTONIC, {355220, 273415554}) = 0
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
read(3, 0xbebd828c, 16) = -1 EAGAIN (Resource temporarily unavailable)
clock_gettime(CLOCK_MONOTONIC, {355220, 277294417}) = 0
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {355220, 280380308}) = 0
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {355220, 282305240}) = 0
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {355220, 284684156}) = 0
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {355220, 286915077}) = 0
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {355220, 290111964}) = 0
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {355220, 291641910}) = 0
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {355220, 293437847}) = 0
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {355220, 295553772}) = 0
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 10705) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {355231, 13213798}) = 0
write(1, " # cancel False False\n", 22) = 22
write(1, " * Not a word in the past 10 sec"..., 49) = 49
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
close(23) = 0
munmap(0xb6f6f000, 4096) = 0
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
gettimeofday({1376379576, 186258}, NULL) = 0
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
open("/usr/local/lib/python2.7/dist-packages/pi-0.1.0-py2.7.egg/static/sounds/pi-cancel.wav", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
open("/usr/local/lib/python2.7/dist-packages/pi-0.1.0-py2.7.egg/static/sounds/pi-cancel.wav", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
ioctl(7, 0x80044121, 0xbebd7ac4) = -1 EPIPE (Broken pipe)
futex(0xe78524, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0xe78520, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1
futex(0xe78500, FUTEX_WAKE_PRIVATE, 1) = 1
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
futex(0x1b82fec, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x1b82fe8, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1
futex(0x1ac5618, FUTEX_WAKE_PRIVATE, 1) = 1
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
write(3, "\1\0\0\0\0\0\0\0", 8) = 8
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 1 ([{fd=3, revents=POLLIN}])
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 1 ([{fd=3, revents=POLLIN}])
read(3, "*\0\0\0\0\0\0\0", 16) = 8
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
read(3, 0xbebd828c, 16) = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}], 2, -1^C <unfinished ...>
Process 12416 detached
问题:我该怎么做才能使这项工作成功?
这是 python 代码。
Listener.py:
import pi
from pi.becore import ScarlettConfig
from recorder import Recorder
from brain import Brain
import os
import json
import tempfile
#import sys
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import pygst
pygst.require('0.10')
gobject.threads_init()
import gst
scarlett_config=ScarlettConfig()
class Listener:
def __init__(self, gobject, gst):
self.failed = 0
self.pipeline = gst.parse_launch(' ! '.join(['alsasrc device=' + scarlett_config.gimmie('audio_input_device'),
'queue',
'audioconvert',
'audioresample',
'queue',
'vader name=vader auto-threshold=true',
'pocketsphinx lm=' + scarlett_config.gimmie('LM') + ' dict=' + scarlett_config.gimmie('DICT') + ' hmm=' + scarlett_config.gimmie('HMM') + ' name=listener',
'fakesink dump=1']))
listener = self.pipeline.get_by_name('listener')
listener.connect('result', self.__result__)
listener.set_property('configured', True)
print "KEYWORDS WE'RE LOOKING FOR: " + scarlett_config.gimmie('ourkeywords')
bus = self.pipeline.get_bus()
bus.add_signal_watch()
bus.connect('message::application', self.__application_message__)
self.pipeline.set_state(gst.STATE_PLAYING)
def result(self, hyp, uttid):
if hyp in scarlett_config.gimmie('ourkeywords'):
self.failed = 0
self.listen()
else:
self.failed += 1
if self.failed > 4:
pi.speak("" + scarlett_config.gimmie('scarlett_owner') + ", if you need me, just say my name.")
self.failed = 0
def listen(self):
self.pipeline.set_state(gst.STATE_PAUSED)
pi.play('pi-listening')
Recorder(self)
def cancel_listening(self):
pi.play('pi-cancel')
self.pipeline.set_state(gst.STATE_PLAYING)
###[ ........MUSIC SUFF HERE........ ]
def __result__(self, listener, text, uttid):
struct = gst.Structure('result')
struct.set_value('hyp', text)
struct.set_value('uttid', uttid)
listener.post_message(gst.message_new_application(listener, struct))
def __application_message__(self, bus, msg):
msgtype = msg.structure.get_name()
if msgtype == 'result':
self.result(msg.structure['hyp'], msg.structure['uttid'])
这是记录器.py:
import pi
from pi.becore import ScarlettConfig
import os
import tempfile
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import pygst
pygst.require('0.10')
gobject.threads_init()
import gst
scarlett_config=ScarlettConfig()
class Recorder:
def __init__(self, listener):
self.listener = listener
self.started = False
self.finished = False
self.recording = tempfile.mktemp(suffix='pi.wav')
self.pipeline = gst.parse_launch(' ! '.join(['alsasrc device=' + scarlett_config.gimmie('audio_input_device'),
'queue',
'audioconvert',
'queue',
'audioresample',
'queue',
'vader name=vader auto-threshold=false',
'fakesink dump=1']))
print "Bossjones Note: What is the current PIPLINE state BEFORE we're recording" + self.pipeline.get_state()
self.recorder = gst.parse_launch(' ! '.join(['alsasrc device=' + scarlett_config.gimmie('audio_input_device'),
'queue',
'audioconvert',
'audioresample',
'audio/x-raw-int,rate=16000,width=16,channels=1,endianness=(int)1234',
'wavenc',
'filesink location=' + self.recording]))
print "Bossjones Note: Technically we're suppose to be recording to this location: " + self.recording
vader = self.pipeline.get_by_name('vader')
vader.connect('vader_start', self.__start__)
vader.connect('vader_stop', self.__stop__)
bus = self.pipeline.get_bus()
bus.add_signal_watch()
bus.connect('message::application', self.__application_message__)
self.pipeline.set_state(gst.STATE_PLAYING)
self.recorder.set_state(gst.STATE_PLAYING)
print " * Listening closely..."
gobject.timeout_add_seconds(10, self.cancel)
def start(self):
self.started = True
print " * Recording..."
def stop(self):
print " * (silence)"
gobject.timeout_add_seconds(1, self.stop_now)
def stop_now(self):
print " # stop_now"
if self.finished == True:
self.listener.cancel_listening()
return
self.finished = True
print " * Stored recording to ", self.recording
self.pipeline.set_state(gst.STATE_NULL)
self.recorder.set_state(gst.STATE_NULL)
print " * Converting to FLAC..."
os.system("ffmpeg -i %s -y %s" % (self.recording, self.recording))
#os.unlink(self.recording)
os.system("sox %s %s.final.wav noisered %s/static/noise.prof 0.21" % (self.recording, self.recording, pi.PWD))
os.system("flac -f --best --sample-rate 16000 -o %s.flac %s.final.wav 2>/dev/null" % (self.recording, self.recording))
os.unlink(self.recording + ".final.wav")
print " * Done."
self.listener.answer(self.recording + '.flac')
def cancel(self):
print " # cancel", self.finished, self.started
if self.finished == True:
print " # cancel - noop"
return
if self.started == False:
self.finished = True
print " * Not a word in the past 10 seconds, cancelling"
self.pipeline.set_state(gst.STATE_NULL)
self.recorder.set_state(gst.STATE_NULL)
self.listener.cancel_listening()
def __start__(self, vader, arg0):
print " # vader:start"
struct = gst.Structure('vader_start')
struct.set_value('arg0', arg0)
vader.post_message(gst.message_new_application(vader, struct))
def __stop__(self, vader, arg0):
print " # vader:stop"
struct = gst.Structure('vader_stop')
struct.set_value('arg0', arg0)
vader.post_message(gst.message_new_application(vader, struct))
def __application_message__(self, bus, msg):
msgtype = msg.structure.get_name()
if msgtype == 'vader_stop':
self.stop()
elif msgtype == 'vader_start':
self.start()
<小时/>
关于调试此问题的最佳方法的想法?
谢谢。
最佳答案
因此,作为启动线,您需要这样的东西:
gst-launch alsasrc device=hw:1 ! queue ! audioconvert ! audioresample ! "audio/x-raw-int, rate=16000, width=16, depth=16, channels=1" ! tee name=t ! queue ! audioresample ! "audio/x-raw-int, rate=8000" ! fvader name=vader auto-threshold=true ! pocketsphinx lm=/home/pi/dev/scarlettPi/config/speech/lm/scarlett.lm dict=/home/pi/dev/scarlettPi/config/speech/dict/scarlett.dic hmm=/usr/local/share/pocketsphinx/model/hmm/en_US/hub4wsj_sc_8k name=listener ! fakesink dump=1 t. ! valve drop=0 ! queue ! wavenc ! filesink location=test.wav async=0
这个想法是,一个 alsasrc 代表您的麦克风,并且由于这可能是独占访问,因此您不应该启动另一个 alsasrc 来访问同一设备。这也有助于获得更好的代码,因为您希望从进行语音检测的同一设备进行记录(据我所知),并且通过使用相同的源,您可以保证情况会如此。
现在,为了在 python 中执行此操作,您可能应该设置管道“正确地”而不是进行解析启动,这意味着您必须实例化每个元素:
self.recording_valve = gst.element_factory_make('valve')
将它们添加到您的管道中:
self.pipeline.add (self.recording_valve)
然后链接它们:
self.recording_valve.link (self.next_element)
...这是 parse-launch 在内部执行的操作,但是,在开始和停止记录时,您现在可以执行以下操作:
self.recording_valve.set_property('drop', False)
开始录制,并且
self.recording_valve.set_property('drop', True)
停止。
(记住最初将 drop 设置为 True,因为默认情况下它是 False)
将所有这些放在一起的最后一部分是了解 T 恤及其请求垫。它可以有任意数量的 src-pad,您可以执行以下操作来链接它:
self.tee.get_request_pad('src%d').link(self.recording_valve_queue.get_pad('sink'))
基本上,您从Tee请求一个srcpad,并将其链接到阀门的sinkpad。您需要对每个 T 恤的分支执行此操作两次。
将其全部启动并运行,您应该会得到一些有用的东西。
关于python - Pocketsphinx + Gstreamer 竞赛条件? Pocketsphinx无法在Python脚本中同时收听音频+录音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18220129/
我正在处理一组标记为 160 个组的 173k 点。我想通过合并最接近的(到 9 或 10 个组)来减少组/集群的数量。我搜索过 sklearn 或类似的库,但没有成功。 我猜它只是通过 knn 聚类
我有一个扁平数字列表,这些数字逻辑上以 3 为一组,其中每个三元组是 (number, __ignored, flag[0 or 1]),例如: [7,56,1, 8,0,0, 2,0,0, 6,1,
我正在使用 pipenv 来管理我的包。我想编写一个 python 脚本来调用另一个使用不同虚拟环境(VE)的 python 脚本。 如何运行使用 VE1 的 python 脚本 1 并调用另一个 p
假设我有一个文件 script.py 位于 path = "foo/bar/script.py"。我正在寻找一种在 Python 中通过函数 execute_script() 从我的主要 Python
这听起来像是谜语或笑话,但实际上我还没有找到这个问题的答案。 问题到底是什么? 我想运行 2 个脚本。在第一个脚本中,我调用另一个脚本,但我希望它们继续并行,而不是在两个单独的线程中。主要是我不希望第
我有一个带有 python 2.5.5 的软件。我想发送一个命令,该命令将在 python 2.7.5 中启动一个脚本,然后继续执行该脚本。 我试过用 #!python2.7.5 和http://re
我在 python 命令行(使用 python 2.7)中,并尝试运行 Python 脚本。我的操作系统是 Windows 7。我已将我的目录设置为包含我所有脚本的文件夹,使用: os.chdir("
剧透:部分解决(见最后)。 以下是使用 Python 嵌入的代码示例: #include int main(int argc, char** argv) { Py_SetPythonHome
假设我有以下列表,对应于及时的股票价格: prices = [1, 3, 7, 10, 9, 8, 5, 3, 6, 8, 12, 9, 6, 10, 13, 8, 4, 11] 我想确定以下总体上最
所以我试图在选择某个单选按钮时更改此框架的背景。 我的框架位于一个类中,并且单选按钮的功能位于该类之外。 (这样我就可以在所有其他框架上调用它们。) 问题是每当我选择单选按钮时都会出现以下错误: co
我正在尝试将字符串与 python 中的正则表达式进行比较,如下所示, #!/usr/bin/env python3 import re str1 = "Expecting property name
考虑以下原型(prototype) Boost.Python 模块,该模块从单独的 C++ 头文件中引入类“D”。 /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c)
如何编写一个程序来“识别函数调用的行号?” python 检查模块提供了定位行号的选项,但是, def di(): return inspect.currentframe().f_back.f_l
我已经使用 macports 安装了 Python 2.7,并且由于我的 $PATH 变量,这就是我输入 $ python 时得到的变量。然而,virtualenv 默认使用 Python 2.6,除
我只想问如何加快 python 上的 re.search 速度。 我有一个很长的字符串行,长度为 176861(即带有一些符号的字母数字字符),我使用此函数测试了该行以进行研究: def getExe
list1= [u'%app%%General%%Council%', u'%people%', u'%people%%Regional%%Council%%Mandate%', u'%ppp%%Ge
这个问题在这里已经有了答案: Is it Pythonic to use list comprehensions for just side effects? (7 个答案) 关闭 4 个月前。 告
我想用 Python 将两个列表组合成一个列表,方法如下: a = [1,1,1,2,2,2,3,3,3,3] b= ["Sun", "is", "bright", "June","and" ,"Ju
我正在运行带有最新 Boost 发行版 (1.55.0) 的 Mac OS X 10.8.4 (Darwin 12.4.0)。我正在按照说明 here构建包含在我的发行版中的教程 Boost-Pyth
学习 Python,我正在尝试制作一个没有任何第 3 方库的网络抓取工具,这样过程对我来说并没有简化,而且我知道我在做什么。我浏览了一些在线资源,但所有这些都让我对某些事情感到困惑。 html 看起来
我是一名优秀的程序员,十分优秀!