bro
This commit is contained in:
1 parent
de41a02749
commit
9af09cebd3
764 files changed
+54218
-78859
No files matched your search
@@ -1,23 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
"""pygame.examples.audiocapture
|
||||
""" pygame.examples.audiocapture
|
||||
|
||||
A pygame 2 experiment.
|
||||
|
||||
* record sound from a microphone
|
||||
* play back the recorded sound
|
||||
"""
|
||||
|
||||
import pygame as pg
|
||||
import time
|
||||
|
||||
import pygame
|
||||
from pygame._sdl2 import (
|
||||
AUDIO_ALLOW_FORMAT_CHANGE,
|
||||
AUDIO_F32,
|
||||
AudioDevice,
|
||||
get_audio_device_names,
|
||||
AudioDevice,
|
||||
AUDIO_F32,
|
||||
AUDIO_ALLOW_FORMAT_CHANGE,
|
||||
)
|
||||
from pygame._sdl2.mixer import set_post_mix
|
||||
|
||||
|
||||
pg.mixer.pre_init(44100, 32, 2, 512)
|
||||
pg.init()
|
||||
|
||||
# init_subsystem(INIT_AUDIO)
|
||||
names = get_audio_device_names(True)
|
||||
print(names)
|
||||
|
||||
sounds = []
|
||||
sound_chunks = []
|
||||
|
||||
@@ -41,42 +48,31 @@ def postmix_callback(postmix, audiomemoryview):
|
||||
print(postmix)
|
||||
|
||||
|
||||
def main():
|
||||
pygame.mixer.pre_init(44100, 32, 2, 512)
|
||||
pygame.init()
|
||||
set_post_mix(postmix_callback)
|
||||
|
||||
# init_subsystem(INIT_AUDIO)
|
||||
names = get_audio_device_names(True)
|
||||
print(names)
|
||||
audio = AudioDevice(
|
||||
devicename=names[0],
|
||||
iscapture=True,
|
||||
frequency=44100,
|
||||
audioformat=AUDIO_F32,
|
||||
numchannels=2,
|
||||
chunksize=512,
|
||||
allowed_changes=AUDIO_ALLOW_FORMAT_CHANGE,
|
||||
callback=callback,
|
||||
)
|
||||
# start recording.
|
||||
audio.pause(0)
|
||||
|
||||
set_post_mix(postmix_callback)
|
||||
print(audio)
|
||||
|
||||
audio = AudioDevice(
|
||||
devicename=names[0],
|
||||
iscapture=True,
|
||||
frequency=44100,
|
||||
audioformat=AUDIO_F32,
|
||||
numchannels=2,
|
||||
chunksize=512,
|
||||
allowed_changes=AUDIO_ALLOW_FORMAT_CHANGE,
|
||||
callback=callback,
|
||||
)
|
||||
# start recording.
|
||||
audio.pause(0)
|
||||
|
||||
print(audio)
|
||||
|
||||
print(f"recording with '{names[0]}'")
|
||||
time.sleep(5)
|
||||
|
||||
print("Turning data into a pygame.mixer.Sound")
|
||||
sound = pygame.mixer.Sound(buffer=b"".join(sound_chunks))
|
||||
|
||||
print("playing back recorded sound")
|
||||
sound.play()
|
||||
time.sleep(5)
|
||||
pygame.quit()
|
||||
print(f"recording with '{names[0]}'")
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
print("Turning data into a pg.mixer.Sound")
|
||||
sound = pg.mixer.Sound(buffer=b"".join(sound_chunks))
|
||||
|
||||
print("playing back recorded sound")
|
||||
sound.play()
|
||||
time.sleep(5)
|
||||
pg.quit()
|
||||
Reference in new issue
Block a user