当前位置: 首页>>代码示例>>Python>>正文


Python pyaudio.paInt16方法代码示例

本文整理汇总了Python中pyaudio.paInt16方法的典型用法代码示例。如果您正苦于以下问题:Python pyaudio.paInt16方法的具体用法?Python pyaudio.paInt16怎么用?Python pyaudio.paInt16使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyaudio的用法示例。


在下文中一共展示了pyaudio.paInt16方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __enter__

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def __enter__(self):
        self._audio_interface = pyaudio.PyAudio()
        self._audio_stream = self._audio_interface.open(
            # format=pyaudio.paInt16,
            format=pyaudio.paFloat32,
            # The API currently only supports 1-channel (mono) audio
            # https://goo.gl/z757pE
            channels=1,
            rate=self._rate,
            input=True,
            frames_per_buffer=self._chunk,
            input_device_index=self._device,
            # Run the audio stream asynchronously to fill the buffer object.
            # This is necessary so that the input device's buffer doesn't
            # overflow while the calling thread makes network requests, etc.
            stream_callback=self._fill_buffer,
        )

        self.closed = False

        return self 
开发者ID:pytorch,项目名称:audio,代码行数:23,代码来源:vad.py

示例2: __enter__

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def __enter__(self):
		self._audio_interface = pyaudio.PyAudio()
		self._audio_stream = self._audio_interface.open(
			format=pyaudio.paInt16,
			channels=1, rate=self._rate,
			input=True, frames_per_buffer=self._chunk,
			# Run the audio stream asynchronously to fill the buffer object.
			# This is necessary so that the input device's buffer doesn't
			# overflow while the calling thread makes network requests, etc.
			stream_callback=self._fill_buffer,
		)

		self.closed = False

		return self

	#def __exit__(self, type, value, traceback): 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:19,代码来源:proj2_yt_mvp.py

示例3: run

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def run(self):
		self.mic_stream = self.p.open(format=pyaudio.paInt16,
			channels=self.channels,
			rate=self.sample_rate,
			input=True,
			frames_per_buffer=self.blocksize)
			
		self.running = True
		while self.mic_stream and self.running:
			input_data = self.mic_stream.read(self.blocksize)
			if input_data:
				self.audio_buffer.write(input_data)

		#Shutdown record command
		if(self.mic_stream):
			self.mic_stream.close()
			self.mic_stream = None 
开发者ID:nyumaya,项目名称:nyumaya_audio_recognition,代码行数:19,代码来源:cross_record.py

示例4: __init__

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def __init__(self):
        # Audio stream input setup
        FORMAT = pyaudio.paInt16
        CHANNELS = 1
        RATE = 16000
        self.CHUNK = 4096
        self.audio = pyaudio.PyAudio()
        self.stream = self.audio.open(format=FORMAT, channels=CHANNELS,
                                      rate=RATE, input=True,
                                      frames_per_buffer=self.CHUNK,
                                      stream_callback=self.get_data)
        self._buff = Queue.Queue()  # Buffer to hold audio data
        self.closed = False

        # ROS Text Publisher
        self.text_pub = rospy.Publisher('/google_client/text', String, queue_size=10)

        # Context clues in yaml file
        rospack = rospkg.RosPack()
        yamlFileDir = rospack.get_path('dialogflow_ros') + '/config/context.yaml'
        with open(yamlFileDir, 'r') as f:
            self.context = yaml.load(f) 
开发者ID:piraka9011,项目名称:dialogflow_ros,代码行数:24,代码来源:google_client.py

示例5: __init__

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def __init__(self):
        # Audio stream input setup
        FORMAT = pyaudio.paInt16
        CHANNELS = 1
        RATE = 16000
        self.CHUNK = 4096
        self.audio = pyaudio.PyAudio()
        self.stream = self.audio.open(format=FORMAT, channels=CHANNELS,
                                      rate=RATE, input=True,
                                      frames_per_buffer=self.CHUNK,
                                      stream_callback=self._get_data)
        self._buff = Queue.Queue()  # Buffer to hold audio data
        self.closed = False

        # ROS Text Publisher
        text_topic = rospy.get_param('/text_topic', '/dialogflow_text')
        self.text_pub = rospy.Publisher(text_topic, String, queue_size=10) 
开发者ID:piraka9011,项目名称:dialogflow_ros,代码行数:19,代码来源:mic_client.py

示例6: __init__

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def __init__(self):
        FORMAT = pyaudio.paInt16
        CHANNELS = 1
        RATE = 16000
        CHUNK = 4096
        self.audio = pyaudio.PyAudio()
        self.stream = self.audio.open(format=FORMAT, channels=CHANNELS, rate=RATE,
                                      input=True, frames_per_buffer=CHUNK,
                                      stream_callback=self._callback)
        self.serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.read_list = [self.serversocket]

        self._server_name = rospy.get_param('/dialogflow_client/server_name',
                                            '127.0.0.1')
        self._port = rospy.get_param('/dialogflow_client/port', 4444)

        rospy.loginfo("DF_CLIENT: Audio Server Started!") 
开发者ID:piraka9011,项目名称:dialogflow_ros,代码行数:19,代码来源:audio_server.py

示例7: run

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def run(self):
        self.logger.debug("Start to recording...")
        self.logger.debug("  Time = %s"%self.time)
        self.logger.debug("  Sample Rate = %s"%self.sr)
        self.start_time = time.time()
        pa=PyAudio()
        stream=pa.open(format = paInt16,channels=1, rate=self.sr,input=True, frames_per_buffer=self.frames_per_buffer)
        my_buf=[]
        count=0
        if self.time is None:
            total_count = 1e10
        else:
            total_count = self.time * self.sr / self.batch_num
        while count< total_count and self.__running.isSet():
            datawav = stream.read(self.batch_num, exception_on_overflow = True)
            datause = np.fromstring(datawav,dtype = np.short)
            for w in datause:
                self.buffer.put(w)
            count+=1
        stream.close() 
开发者ID:mhy12345,项目名称:rcaudio,代码行数:22,代码来源:core_recorder.py

示例8: __init__

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def __init__(self):
        
        self.open = True
        self.rate = 44100
        self.frames_per_buffer = 1024
        self.channels = 2
        self.format = pyaudio.paInt16
        self.audio_filename = "temp_audio.wav"
        self.audio = pyaudio.PyAudio()
        self.stream = self.audio.open(format=self.format,
                                      channels=self.channels,
                                      rate=self.rate,
                                      input=True,
                                      frames_per_buffer = self.frames_per_buffer)
        self.audio_frames = []


    # Audio starts being recorded 
开发者ID:JRodrigoF,项目名称:AVrecordeR,代码行数:20,代码来源:AVrecordeR.py

示例9: __enter__

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def __enter__(self):
		with SuperManager.getInstance().commons.shutUpAlsaFFS():
			self._audio_interface = pyaudio.PyAudio()

		self._audio_stream = self._audio_interface.open(
			format=pyaudio.paInt16,
			# The API currently only supports 1-channel (mono) audio
			# https://goo.gl/z757pE
			channels=1, rate=self._rate,
			input=True, frames_per_buffer=self._chunk,
			# Run the audio stream asynchronously to fill the buffer object.
			# This is necessary so that the input device's buffer doesn't
			# overflow while the calling thread makes network requests, etc.
			stream_callback=self._fill_buffer,
		)

		self.closed = False

		return self 
开发者ID:project-alice-assistant,项目名称:ProjectAlice,代码行数:21,代码来源:MicrophoneStream.py

示例10: main

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def main():
    # prepare audio recorder
    p = pyaudio.PyAudio()
    stream = p.open(
        format=pyaudio.paInt16,
        channels=1,
        rate=16000,
        input=True,
        stream_callback=callback)
    stream.start_stream()

    # prepare keyboard listener
    with keyboard.Listener(
            on_press=on_press, on_release=on_release) as listener:
        listener.join()

    # close up
    stream.stop_stream()
    stream.close()
    p.terminate() 
开发者ID:Pelhans,项目名称:ZASR_tensorflow,代码行数:22,代码来源:demo_client.py

示例11: __enter__

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def __enter__(self):
        self._audio_interface = pyaudio.PyAudio()
        self._audio_stream = self._audio_interface.open(
            format=pyaudio.paInt16,
            # The API currently only supports 1-channel (mono) audio
            # https://goo.gl/z757pE
            channels=1, rate=self._rate,
            input=True, frames_per_buffer=self._chunk,
            # Run the audio stream asynchronously to fill the buffer object.
            # This is necessary so that the input device's buffer doesn't
            # overflow while the calling thread makes network requests, etc.
            stream_callback=self._fill_buffer,
        )

        self.closed = False

        return self 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:19,代码来源:transcribe_streaming_mic.py

示例12: predict_file

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def predict_file(dec, pyaudio, path, frames, args, rate = 16000, format = pyaudio.paInt16, save = False):
    wf = wave.open(path, 'wb')
    wf.setnchannels(1)
    wf.setsampwidth(pyaudio.get_sample_size(format))
    wf.setframerate(rate)
    #this code works for only for pulseaudio
    #wf.writeframes(b''.join(frames))
    wf.writeframes(frames)
    wf.close()

    results = dec.predict_file(path, feat_mode = args.feat_mode, feat_dim = args.feat_dim, three_d = args.three_d)
    
    if save == False:
        os.remove(path)
    if args.predict_mode == 0:
        task_outputs = dec.returnDiff(results)
    elif args.predict_mode == 1:
        task_outputs = dec.returnLabel(results)
    else:
        task_outputs = dec.returnClassDist(results)
    return task_outputs

#main loop for speech emotion recognition 
开发者ID:batikim09,项目名称:LIVE_SER,代码行数:25,代码来源:offline_ser.py

示例13: startStream

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def startStream(self):
        self.stream = py_audio.open(format = pyaudio.paInt16,
                                    channels = 1,
                                    rate = self.device_rate,
                                    input = True,
                                    input_device_index = self.device_id,
                                    frames_per_buffer = self.frames_per_buffer)
            
        # overflows = 0
        # prev_ovf_time = time.time()
        while True:
            try:
                y = np.fromstring(self.stream.read(self.frames_per_buffer), dtype=np.int16)
                y = y.astype(np.float32)
                self.callback_func(y)
            except IOError:
                pass
                # overflows += 1
                # if time.time() > prev_ovf_time + 1:
                #     prev_ovf_time = time.time()
                #     if config.settings["configuration"]["USE_GUI"]:
                #         gui.label_error.setText('Audio buffer has overflowed {} times'.format(overflows))
                #     else:
                #         print('Audio buffer has overflowed {} times'.format(overflows)) 
开发者ID:not-matt,项目名称:Systematic-LEDs,代码行数:26,代码来源:main.py

示例14: get_microphone_level

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def get_microphone_level():
    """
    source: http://stackoverflow.com/questions/26478315/getting-volume-levels-from-pyaudio-for-use-in-arduino
    audioop.max alternative to audioop.rms
    """
    chunk = 1024
    FORMAT = pyaudio.paInt16
    CHANNELS = 1
    RATE = 44100
    p = pyaudio.PyAudio()

    s = p.open(format=FORMAT,
               channels=CHANNELS,
               rate=RATE,
               input=True,
               frames_per_buffer=chunk)
    global levels
    while True:
        data = s.read(chunk)
        mx = audioop.rms(data, 2)
        if len(levels) >= 100:
            levels = []
        levels.append(mx) 
开发者ID:atuldo,项目名称:real-time-plot-microphone-kivy,代码行数:25,代码来源:main.py

示例15: run

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paInt16 [as 别名]
def run(self):
        pya = PyAudio()
        self._stream = pya.open(
            format=paInt16,
            channels=1,
            rate=SAMPLE_RATE,
            input=True,
            frames_per_buffer=WINDOW_SIZE,
            stream_callback=self._process_frame,
        )
        self._stream.start_stream()

        while self._stream.is_active() and not raw_input():
            time.sleep(0.1)

        self._stream.stop_stream()
        self._stream.close()
        pya.terminate() 
开发者ID:aniawsz,项目名称:rtmonoaudio2midi,代码行数:20,代码来源:audiostream.py


注:本文中的pyaudio.paInt16方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。