mirror of
https://github.com/romanz/amodem.git
synced 2026-03-24 11:22:00 +08:00
move wave.py __main__ part to scripts.
This commit is contained in:
32
amodem/wave.py
Executable file → Normal file
32
amodem/wave.py
Executable file → Normal file
@@ -32,35 +32,3 @@ def launch(*args, **kwargs):
|
||||
p = sp.Popen(args=args, **kwargs)
|
||||
p.stop = lambda: os.kill(p.pid, signal.SIGKILL)
|
||||
return p
|
||||
|
||||
if __name__ == '__main__':
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(message)s')
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers()
|
||||
fmt = 'a raw audio file (16 bits at {:.1f} kHz)'.format(Fs / 1e3)
|
||||
recorder = subparsers.add_parser('record', help='record ' + fmt)
|
||||
recorder.add_argument(
|
||||
'filename', default='-',
|
||||
help='path to the audio file to record (otherwise, use stdout)')
|
||||
recorder.set_defaults(func=record)
|
||||
|
||||
player = subparsers.add_parser('play', help='play ' + fmt)
|
||||
player.add_argument(
|
||||
'filename', default='-',
|
||||
help='path to the audio file to play (otherwise, use stdin)')
|
||||
player.set_defaults(func=play)
|
||||
|
||||
args = parser.parse_args()
|
||||
p = args.func(args.filename)
|
||||
|
||||
import sys
|
||||
exitcode = 0
|
||||
try:
|
||||
exitcode = p.wait()
|
||||
except KeyboardInterrupt:
|
||||
p.kill()
|
||||
exitcode = p.wait()
|
||||
|
||||
sys.exit(exitcode)
|
||||
|
||||
33
scripts/wave.py
Executable file
33
scripts/wave.py
Executable file
@@ -0,0 +1,33 @@
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(message)s')
|
||||
|
||||
from amodem import wave
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers()
|
||||
fmt = 'a raw audio file (16 bits at {:.1f} kHz)'.format(wave.Fs / 1e3)
|
||||
recorder = subparsers.add_parser('record', help='record ' + fmt)
|
||||
recorder.add_argument(
|
||||
'filename', default='-',
|
||||
help='path to the audio file to record (otherwise, use stdout)')
|
||||
recorder.set_defaults(func=wave.record)
|
||||
|
||||
player = subparsers.add_parser('play', help='play ' + fmt)
|
||||
player.add_argument(
|
||||
'filename', default='-',
|
||||
help='path to the audio file to play (otherwise, use stdin)')
|
||||
player.set_defaults(func=wave.play)
|
||||
|
||||
args = parser.parse_args()
|
||||
p = args.func(args.filename)
|
||||
|
||||
import sys
|
||||
exitcode = 0
|
||||
try:
|
||||
exitcode = p.wait()
|
||||
except KeyboardInterrupt:
|
||||
p.kill()
|
||||
exitcode = p.wait()
|
||||
|
||||
sys.exit(exitcode)
|
||||
Reference in New Issue
Block a user