import soundfile as sf import sys import os import numpy as np audio_subtype = os.environ.get('AUDIO_SUBTYPE', 'VORBIS') audio_format = 'OGG' channel_cnt = 2 sample_rate = 44100 dtype = os.environ.get('DTYPE','float64') sample_cnt = int(os.environ.get('SAMPLE_CNT', '11235535')) if len(sys.argv) == 2: with sf.SoundFile(sys.argv[1]) as audioin: channels = audioin.read(dtype=dtype, always_2d=True) print("read %d samples" % (len(channels),)) else: channels = np.ndarray((sample_cnt, channel_cnt), dtype=dtype) with sf.SoundFile('crash.ogg', mode='w', samplerate=sample_rate, channels=channel_cnt, subtype=audio_subtype, format=audio_format) as audioout: audioout.write(channels)