Showing
2 changed files
with
36 additions
and
0 deletions
output.mp3
0 → 100644
File mode changed
streamToOut.py
0 → 100644
1 | +import pyaudio | ||
2 | +from pydub import AudioSegment | ||
3 | +from pydub.effects import normalize | ||
4 | + | ||
5 | +# set up PyAudio | ||
6 | +pa = pyaudio.PyAudio() | ||
7 | +stream = pa.open(format=pyaudio.paInt16, | ||
8 | + channels=1, | ||
9 | + rate=44100, | ||
10 | + input=True, | ||
11 | + frames_per_buffer=1024) | ||
12 | + | ||
13 | +# record some audio from the microphone | ||
14 | +audio_data = [] | ||
15 | +for i in range(0, int(44100 / 1024 * 5)): | ||
16 | + data = stream.read(1024) | ||
17 | + audio_data.append(data) | ||
18 | + | ||
19 | +# convert the audio data to a PyDub audio segment | ||
20 | +audio_segment = AudioSegment( | ||
21 | + data=b''.join(audio_data), | ||
22 | + sample_width=2, | ||
23 | + frame_rate=44100, | ||
24 | + channels=1 | ||
25 | +) | ||
26 | + | ||
27 | +# apply an echo effect to the audio segment | ||
28 | +echoed_segment = normalize(audio_segment) | ||
29 | + | ||
30 | +# save the output audio file | ||
31 | +echoed_segment.export("output.mp3", format="mp3") | ||
32 | + | ||
33 | +# clean up | ||
34 | +stream.stop_stream() | ||
35 | +stream.close() | ||
36 | +pa.terminate() |
-
Please register or login to post a comment