How to use the miniaudio.stream_file function in miniaudio

To help you get started, we’ve selected a few miniaudio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github irmen / pyminiaudio / examples / play.py View on Github external
framecount = yield(b"")
        try:
            while True:
                framecount = yield stream.send(framecount)
                print(".", end="", flush=True)
        except StopIteration:
            return

    output_format = info.sample_format
    try:
        filestream = miniaudio.stream_file(filename, output_format=output_format, sample_rate=info.sample_rate)
    except miniaudio.MiniaudioError as x:
        print("Cannot create optimal stream:", x)
        print("Creating stream with different sample format!")
        output_format = miniaudio.SampleFormat.SIGNED16
        filestream = miniaudio.stream_file(filename, output_format=output_format, sample_rate=info.sample_rate,
                                           dither=miniaudio.DitherMode.TRIANGLE)

    stream = progress_stream_wrapper(filestream)
    next(stream)   # start the generator
    device = miniaudio.PlaybackDevice(output_format=output_format, sample_rate=info.sample_rate)
    print("playback device backend:", device.backend, device.format.name, device.sample_rate, "hz")
    device.start(stream)
    input("Audio file playing in the background. Enter to stop playback: ")
    device.close()
github irmen / synthesizer / pyminiaudio / examples / play.py View on Github external
def stream_file(filename):
    def progress_stream_wrapper(stream) -> miniaudio.AudioProducerType:
        framecount = yield(b"")
        try:
            while True:
                framecount = yield stream.send(framecount)
                print(".", end="", flush=True)
        except StopIteration:
            return

    stream = progress_stream_wrapper(miniaudio.stream_file(filename))
    next(stream)   # start the generator
    device = miniaudio.PlaybackDevice()
    print("playback device backend:", device.backend)
    device.start(stream)
    input("Audio file playing in the background. Enter to stop playback: ")
    device.close()
github irmen / pyminiaudio / examples / play.py View on Github external
def stream_file(info, filename):
    def progress_stream_wrapper(stream) -> miniaudio.PlaybackCallbackGeneratorType:
        framecount = yield(b"")
        try:
            while True:
                framecount = yield stream.send(framecount)
                print(".", end="", flush=True)
        except StopIteration:
            return

    output_format = info.sample_format
    try:
        filestream = miniaudio.stream_file(filename, output_format=output_format, sample_rate=info.sample_rate)
    except miniaudio.MiniaudioError as x:
        print("Cannot create optimal stream:", x)
        print("Creating stream with different sample format!")
        output_format = miniaudio.SampleFormat.SIGNED16
        filestream = miniaudio.stream_file(filename, output_format=output_format, sample_rate=info.sample_rate,
                                           dither=miniaudio.DitherMode.TRIANGLE)

    stream = progress_stream_wrapper(filestream)
    next(stream)   # start the generator
    device = miniaudio.PlaybackDevice(output_format=output_format, sample_rate=info.sample_rate)
    print("playback device backend:", device.backend, device.format.name, device.sample_rate, "hz")
    device.start(stream)
    input("Audio file playing in the background. Enter to stop playback: ")
    device.close()
github irmen / synthesizer / pyminiaudio / examples / demo4.py View on Github external
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: ")
github irmen / pyminiaudio / examples / demo4.py View on Github external
return os.path.join(os.path.abspath(os.path.dirname(__file__)), 'samples', filename)


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]


if __name__ == "__main__":
    selected_device = choose_device()
    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: ")