Created
March 20, 2017 15:40
-
-
Save nomelif/b0a2d1bd7d9446b4f48653728eb9d538 to your computer and use it in GitHub Desktop.
Skeleton for on-line voice modification scripts. Requires numpy and PyAudio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyaudio | |
import numpy as np | |
FORMAT = pyaudio.paInt16 | |
CHANNELS = 1 | |
RATE = 44100 | |
CHUNK = 1024 | |
audio = pyaudio.PyAudio() | |
def audioIn(): | |
stream = audio.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK) | |
prev = np.zeros(1024) | |
new_data = np.zeros(1024) | |
while True: | |
prev = new_data | |
new_data = (np.fromstring(stream.read(CHUNK), dtype=np.int16) / (2**15) + 1) / 2 | |
yield prev, new_data | |
def audioOut(): | |
stream = audio.open(output=True, channels=CHANNELS, rate=RATE, format=pyaudio.paInt16) | |
while True: | |
input_data = yield | |
input_data = ((input_data*2 - 1)*(2**15)).astype(np.int16) | |
stream.write(input_data.tostring()) | |
sink = audioOut() | |
next(sink) | |
sink.send(np.zeros(CHUNK*10)) | |
for previous, current in audioIn(): | |
# Do modifications here | |
sink.send(current) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment