Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_devices():
devs = miniaudio.Devices()
devs.get_playbacks()
devs.get_captures()
def choose_device():
devices = miniaudio.Devices()
print("Available recording devices:")
captures = devices.get_captures()
for d in enumerate(captures):
print("{num} = {name}".format(num=d[0], name=d[1]['name']))
choice = int(input("record from which device? "))
return captures[choice]
def choose_device():
devices = miniaudio.Devices()
print("Available playback devices:")
playbacks = devices.get_playbacks()
for d in enumerate(playbacks, 1):
print("{num} = {name}".format(num=d[0], name=d[1]['name']))
choice = int(input("play on which device? "))
return playbacks[choice-1]
import array
from time import sleep
import miniaudio
if __name__ == "__main__":
buffer_chunks = []
def record_to_buffer():
_ = yield
while True:
data = yield
print(".", end="", flush=True)
buffer_chunks.append(data)
devices = miniaudio.Devices()
print("Available recording devices:")
captures = devices.get_captures()
for p in enumerate(captures):
print(p[0], "= ", p[1])
choice = int(input("record from which device? "))
selected_device = captures[choice]
print("Recording from {}".format(selected_device.name))
capture = miniaudio.CaptureDevice(buffersize_msec=1000, sample_rate=44100, device_id=selected_device._id) # TODO: fix ownership of _id? or create copy?
print(capture.format)
generator = record_to_buffer()
print("Recording for 3 seconds")
next(generator)
capture.start(generator)
sleep(3)
import os
import miniaudio
def samples_path(filename):
return os.path.join(os.path.abspath(os.path.dirname(__file__)), 'samples', filename)
if __name__ == "__main__":
devices = miniaudio.Devices()
selected_device = devices.get_playbacks()[0]
print("Playing back through {}".format(selected_device.name))
stream = miniaudio.stream_file(samples_path("music.mp3"))
device = miniaudio.PlaybackDevice(device_id=selected_device.id)
device.start(stream)
input("Audio file playing in the background. Enter to stop playback: ")
import miniaudio
if __name__ == "__main__":
devices = miniaudio.Devices()
print("Backend: {}".format(devices.backend))
print("\n")
out_devices = devices.get_playbacks()
print("Playback Devices")
for device in out_devices:
print(" {}".format(device.name))
print(" {}".format(device.info()))
print("\n")
in_devices = devices.get_captures()
print("Capture Devices")
for device in in_devices:
print(" {}".format(device.name))
print(" {}".format(device.info()))
print("\n")
def choose_devices():
devices = miniaudio.Devices(backends=backends)
print("Available capture devices:")
captures = devices.get_captures()
for d in enumerate(captures, 1):
print("{num} = {name}".format(num=d[0], name=d[1]['name']))
capture_choice = int(input("record from which device? "))
print("\nAvailable playback devices:")
playbacks = devices.get_playbacks()
for d in enumerate(playbacks, 1):
print("{num} = {name}".format(num=d[0], name=d[1]['name']))
playback_choice = int(input("play on which device? "))
return captures[capture_choice-1], playbacks[playback_choice-1]