mirror of
https://github.com/romanz/amodem.git
synced 2026-02-06 00:36:20 +08:00
34 lines
858 B
Python
Executable File
34 lines
858 B
Python
Executable File
#!/usr/bin/env python
|
|
import argparse
|
|
from amodem import audio
|
|
from amodem.config import Configuration
|
|
|
|
"""Script that records audio through an interface
|
|
and stores it into an amodem.config Configuration.
|
|
"""
|
|
|
|
def run(args):
|
|
config = Configuration()
|
|
with open(args.filename, 'wb') as dst:
|
|
interface = audio.Interface(config=config)
|
|
with interface.load(args.audio_library):
|
|
src = interface.recorder()
|
|
size = int(config.sample_size * config.Fs) # one second of audio
|
|
while True:
|
|
dst.write(src.read(size))
|
|
|
|
|
|
def main():
|
|
p = argparse.ArgumentParser()
|
|
p.add_argument('-l', '--audio-library', default='libportaudio.so')
|
|
p.add_argument('filename')
|
|
|
|
try:
|
|
run(args=p.parse_args())
|
|
except KeyboardInterrupt:
|
|
return
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|