sound recording

This commit is contained in:
Frank DeMarco 2018-06-04 20:06:32 -04:00
parent 1f4b3384ed
commit 5ac39f0879
1 changed files with 21 additions and 0 deletions

View File

@ -50,6 +50,16 @@ class VideoRecorder(GameChild):
if recording:
self.frame_length = len(self.get_string())
self.frames = TemporaryFile()
if self.check_command_line("-enable-sound-recording"):
import pyaudio
import wave
self.audio_frames = []
self.audio_recorder = pyaudio.PyAudio()
def audio_callback(in_data, frame_count, time_info, status):
self.audio_frames.append(in_data)
return (in_data, pyaudio.paContinue)
self.audio_stream = self.audio_recorder.open(format=pyaudio.paInt16, channels=2, rate=44100,
input=True, stream_callback=audio_callback)
else:
self.write_frames()
self.recording = recording
@ -69,6 +79,17 @@ class VideoRecorder(GameChild):
path = join(root, "%04i.png" % ii)
save(frombuffer(frame, size, self.frame_format), path)
print "wrote video frames to " + root
if self.check_command_line("-enable-sound-recording"):
self.audio_stream.stop_stream()
self.audio_stream.close()
self.audio_recorder.terminate()
import wave
wf = wave.open(join(root, "audio.wav"), "wb")
wf.setnchannels(2)
wf.setsampwidth(self.audio_recorder.get_sample_size(pyaudio.paInt16))
wf.setframerate(44100)
wf.writeframes(b"".join(self.audio_frames))
wf.close()
def update(self):
ticks = get_ticks()