How to use the miniaudio.wav_write_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 / capture.py View on Github external
selected_device = choose_device()
    capture = miniaudio.CaptureDevice(buffersize_msec=1000, sample_rate=44100, device_id=selected_device["id"])
    generator = record_to_buffer()
    print("Recording for 3 seconds")
    next(generator)
    capture.start(generator)
    sleep(3)
    capture.stop()

    buffer = b"".join(buffer_chunks)
    print("\nRecorded", len(buffer), "bytes")
    print("Wring to ./capture.wav")
    samples = array.array('h')
    samples.frombytes(buffer)
    sound = miniaudio.DecodedSoundFile('capture', capture.nchannels, capture.sample_rate, capture.format, samples)
    miniaudio.wav_write_file('capture.wav', sound)
    print("Recording done")
github irmen / pyminiaudio / examples / streamingconvert.py View on Github external
while True:
    framedata = converter.read(4000)
    if not framedata:
        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 / synthesizer / pyminiaudio / examples / capture.py View on Github external
generator = record_to_buffer()
    print("Recording for 3 seconds")
    next(generator)
    capture.start(generator)
    sleep(3)
    capture.stop()

    buffer = b"".join(buffer_chunks)
    print("\nRecorded", len(buffer), "bytes")
    print("Wring to ./capture.wav")
    samples = array.array('h')
    samples.frombytes(buffer)
    sound = miniaudio.DecodedSoundFile(
        'capture', capture.nchannels, capture.sample_rate,
        capture.sample_width, capture.format, samples)
    miniaudio.wav_write_file('capture.wav', sound)
    print("Recording done")
github irmen / pyminiaudio / examples / convert.py View on Github external
return os.path.join(os.path.abspath(os.path.dirname(__file__)), 'samples', filename)


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)