當前位置: 首頁>>代碼示例>>Python>>正文


Python alsaaudio.PCM_NORMAL屬性代碼示例

本文整理匯總了Python中alsaaudio.PCM_NORMAL屬性的典型用法代碼示例。如果您正苦於以下問題:Python alsaaudio.PCM_NORMAL屬性的具體用法?Python alsaaudio.PCM_NORMAL怎麽用?Python alsaaudio.PCM_NORMAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在alsaaudio的用法示例。


在下文中一共展示了alsaaudio.PCM_NORMAL屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: start

# 需要導入模塊: import alsaaudio [as 別名]
# 或者: from alsaaudio import PCM_NORMAL [as 別名]
def start():
	last = GPIO.input(button)
	while True:
		val = GPIO.input(button)
		GPIO.wait_for_edge(button, GPIO.FALLING) # we wait for the button to be pressed
		GPIO.output(lights[1], GPIO.HIGH)
		inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, device)
		inp.setchannels(1)
		inp.setrate(16000)
		inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
		inp.setperiodsize(500)
		audio = ""
		while(GPIO.input(button)==0): # we keep recording while the button is pressed
			l, data = inp.read()
			if l:
				audio += data
		rf = open(path+'recording.wav', 'w')
		rf.write(audio)
		rf.close()
		inp = None
		alexa() 
開發者ID:alexa-pi,項目名稱:AlexaPiDEPRECATED,代碼行數:23,代碼來源:main.py

示例2: run

# 需要導入模塊: import alsaaudio [as 別名]
# 或者: from alsaaudio import PCM_NORMAL [as 別名]
def run(self):
        # open audio file and device
        audio_file = wave.open(self.soundfile, 'rb')
        audio_device = alsaaudio.PCM(alsaaudio.PCM_PLAYBACK, alsaaudio.PCM_NORMAL, 'default')

        # we are hard coding the audio format!
        audio_device.setchannels(2)
        audio_device.setrate(44100)
        audio_device.setformat(alsaaudio.PCM_FORMAT_S16_LE)
        audio_device.setperiodsize(980)

        # play the audio
        audio_data = audio_file.readframes(980)
        while audio_data:
          audio_device.write(audio_data)
          audio_data = audio_file.readframes(980)

        audio_file.close()

# Class for blinking the leds 
開發者ID:intel,項目名稱:intel-iot-refkit,代碼行數:22,代碼來源:btspeaker.py

示例3: acquire

# 需要導入模塊: import alsaaudio [as 別名]
# 或者: from alsaaudio import PCM_NORMAL [as 別名]
def acquire(self):
        if self._session.is_active():
            try:
                pcm_args = {
                    'type': alsa.PCM_PLAYBACK,
                    'mode': alsa.PCM_NORMAL,
                }
                if self._args.playback_device != 'default':
                    pcm_args['device'] = self._args.playback_device
                else:
                    pcm_args['card'] = self._args.device
                pcm = alsa.PCM(**pcm_args)

                pcm.setchannels(CHANNELS)
                pcm.setrate(RATE)
                pcm.setperiodsize(PERIODSIZE)
                pcm.setformat(alsa.PCM_FORMAT_S16_LE)

                self._device = pcm
                print "AlsaSink: device acquired"
            except alsa.ALSAAudioError as error:
                print "Unable to acquire device: ", error
                self.release() 
開發者ID:Fornoth,項目名稱:spotify-connect-web,代碼行數:25,代碼來源:console_callbacks.py

示例4: open_stream

# 需要導入模塊: import alsaaudio [as 別名]
# 或者: from alsaaudio import PCM_NORMAL [as 別名]
def open_stream(self, bits, channels, rate, chunksize=1024, output=True):
        # Check if format is supported
        is_supported_fmt = self.supports_format(bits, channels, rate,
                                                output=output)
        if not is_supported_fmt:
            msg_fmt = ("ALSAAudioDevice ({name}) doesn't support " +
                       "%s format (Int{bits}, {channels}-channel at" +
                       " {rate} Hz)") % ('output' if output else 'input')
            msg = msg_fmt.format(name=self.name,
                                 bits=bits,
                                 channels=channels,
                                 rate=rate)
            self._logger.critical(msg)
            raise Exception(msg)
        # Everything looks fine, open the PCM stream
        pcm_type = alsaaudio.PCM_PLAYBACK if output else alsaaudio.PCM_CAPTURE
        stream = alsaaudio.PCM(type=pcm_type,
                               mode=alsaaudio.PCM_NORMAL,
                               device=self.name)
        stream.setchannels(channels)
        stream.setrate(rate)
        stream.setformat(bits_to_samplefmt(bits))
        stream.setperiodsize(chunksize)
        self._logger.debug("%s stream opened on device '%s' (%d Hz, %d " +
                           "channel, %d bit)", "output" if output else "input",
                           self.slug, rate, channels, bits)
        try:
            yield stream
        finally:
            stream.close()
            self._logger.debug("%s stream closed on device '%s'",
                               "output" if output else "input", self.slug) 
開發者ID:niutool,項目名稱:xuebao,代碼行數:34,代碼來源:alsaaudioengine.py

示例5: play

# 需要導入模塊: import alsaaudio [as 別名]
# 或者: from alsaaudio import PCM_NORMAL [as 別名]
def play(self, file_path):

        if self.convert:
            self.convert_mp3_to_wav(file_path_mp3=file_path)
        f = wave.open(file_path, 'rb')
        pcm_type = alsaaudio.PCM_PLAYBACK
        stream = alsaaudio.PCM(type=pcm_type,
                               mode=alsaaudio.PCM_NORMAL,
                               device=self.device)
        # Set attributes
        stream.setchannels(f.getnchannels())
        stream.setrate(f.getframerate())
        bits = f.getsampwidth()*8
        stream.setformat(bits_to_samplefmt(bits))        
        stream.setperiodsize(CHUNK)
        
        logger.debug("[PyAlsaAudioPlayer] %d channels, %d sampling rate, %d bit" % (f.getnchannels(),
                                                                                    f.getframerate(),
                                                                                    bits))
        
        data = f.readframes(CHUNK)
        while data:
            # Read data from stdin
            stream.write(data)
            data = f.readframes(CHUNK)
     
        f.close()
        stream.close() 
開發者ID:kalliope-project,項目名稱:kalliope,代碼行數:30,代碼來源:pyalsaaudio.py

示例6: open_stream

# 需要導入模塊: import alsaaudio [as 別名]
# 或者: from alsaaudio import PCM_NORMAL [as 別名]
def open_stream(self, bits, channels, rate, chunksize=1024, output=True):
        # Check if format is supported
        is_supported_fmt = self.supports_format(bits, channels, rate,
                                                output=output)
        if not is_supported_fmt:
            msg_fmt = ("ALSAAudioDevice ({name}) doesn't support " +
                       "%s format (Int{bits}, {channels}-channel at" +
                       " {rate} Hz)") % ('output' if output else 'input')
            msg = msg_fmt.format(name=self.name,
                                 bits=bits,
                                 channels=channels,
                                 rate=rate)
            self._logger.critical(msg)
            raise Exception(msg)
        # Everything looks fine, open the PCM stream
        pcm_type = alsaaudio.PCM_PLAYBACK if output else alsaaudio.PCM_CAPTURE
        stream = alsaaudio.PCM(type=pcm_type,
                               mode=alsaaudio.PCM_NORMAL,
                               device='default')
        stream.setchannels(channels)
        stream.setrate(rate)
        stream.setformat(bits_to_samplefmt(bits))
        stream.setperiodsize(chunksize)
        self._logger.debug("%s stream opened on device '%s' (%d Hz, %d " +
                           "channel, %d bit)", "output" if output else "input",
                           self.slug, rate, channels, bits)
        try:
            yield stream
        finally:
            stream.close()
            self._logger.debug("%s stream closed on device '%s'",
                               "output" if output else "input", self.slug) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:34,代碼來源:defaultaudio.py

示例7: _record

# 需要導入模塊: import alsaaudio [as 別名]
# 或者: from alsaaudio import PCM_NORMAL [as 別名]
def _record(self, cb):
        inp = None
        try:
            inp = alsaaudio.PCM(
                alsaaudio.PCM_CAPTURE,
                alsaaudio.PCM_NORMAL,
                device=self.record_device,
            )
            inp.setchannels(1)
            inp.setrate(16000)
            inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
            inp.setperiodsize(1600)  # 100ms
            finalize = False
            while not finalize:
                l, data = inp.read()
                if not self.currently_recording:
                    finalize = True
                if l or finalize:
                    # self.recorded_raw.write(data)
                    cb(data, finalize)
        except Exception:
            print(traceback.format_exc())
        finally:
            self.currently_recording = False
            if inp:
                inp.close() 
開發者ID:nabaztag2018,項目名稱:pynab,代碼行數:28,代碼來源:sound_alsa.py


注:本文中的alsaaudio.PCM_NORMAL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。