How to use the miniaudio.get_file_info 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
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()


if __name__ == "__main__":
    if len(sys.argv) != 2:
        raise SystemExit("use one argument: filename")
    info = miniaudio.get_file_info(sys.argv[1])
    show_info(info)
    stream_file(info, sys.argv[1])
github irmen / synthesizer / pyminiaudio / examples / play.py View on Github external
def show_info(filename):
    info = miniaudio.get_file_info(filename)
    print("file:", info.name)
    print("format:", info.file_format)
    print("{} channels, {} khz, {:.1f} seconds".format(info.nchannels, info.sample_rate, info.duration))
    print("{} bytes per sample: {}".format(info.sample_width, info.sample_format_name))
github irmen / pyminiaudio / examples / streamingconvert.py View on Github external
break
    print("got chunk of size", len(framedata))
    framechunks.append(framedata)

print("\nGot", len(framechunks), "total frame chunks")

# convert the frames to bytes and write it to a file
samples = array.array('B')
for f in framechunks:
    samples.extend(f)
outputfile = miniaudio.DecodedSoundFile("converted", converter.out_channels,
                                        converter.out_samplerate, converter.out_format, samples)
miniaudio.wav_write_file("converted.wav", outputfile)

print("\nConverted sound written to ./converted.wav")
output_info = miniaudio.get_file_info("converted.wav")
print(output_info)
github irmen / pyminiaudio / examples / convert.py View on Github external
src = miniaudio.decode_file(samples_path("music.ogg"), dither=miniaudio.DitherMode.TRIANGLE)
print("Source: ", src)

result = miniaudio.DecodedSoundFile("result", 1, 22050, miniaudio.SampleFormat.UNSIGNED8, array.array('b'))
converted_frames = miniaudio.convert_frames(src.sample_format, src.nchannels, src.sample_rate, src.samples.tobytes(),
                                            result.sample_format, result.nchannels, result.sample_rate)
# note: currently it is not possible to provide a dithermode to convert_frames()

result.num_frames = int(len(converted_frames) / result.nchannels / result.sample_width)
result.samples.frombytes(converted_frames)


miniaudio.wav_write_file("converted.wav", result)
print("Converted sound written to ./converted.wav")

output_info = miniaudio.get_file_info("converted.wav")
print(output_info)