-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_processor.py
35 lines (30 loc) · 940 Bytes
/
audio_processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pyaudio
import numpy as np
class AudioStream:
def __init__(self):
self.CHUNK = 1024 * 2
self.FORMAT = pyaudio.paInt16
self.CHANNELS = 1
self.RATE = 44100
self.p = pyaudio.PyAudio()
self.stream = None
def start_stream(self, callback):
self.stream = self.p.open(
format=self.FORMAT,
channels=self.CHANNELS,
rate=self.RATE,
input=True,
output=True,
frames_per_buffer=self.CHUNK,
stream_callback=callback
)
self.stream.start_stream()
def stop_stream(self):
if self.stream:
self.stream.stop_stream()
self.stream.close()
if __name__ == '__main__':
# Проверка работы ввода и вывода аудио
audio_stream = AudioStream()
audio_stream.start_stream()
audio_stream.stop_stream()