mirror of
https://github.com/romanz/amodem.git
synced 2026-03-17 23:26:01 +08:00
pylint wave.py
This commit is contained in:
21
wave.py
21
wave.py
@@ -7,17 +7,22 @@ import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
from common import Fs
|
||||
Fs = int(Fs) # sampling rate
|
||||
Fs = int(Fs) # sampling rate
|
||||
bits_per_sample = 16
|
||||
bytes_per_second = bits_per_sample * Fs / 8.0
|
||||
|
||||
audio_format = 'S{}_LE'.format(bits_per_sample) # PCM signed little endian
|
||||
audio_format = 'S{}_LE'.format(bits_per_sample) # PCM signed little endian
|
||||
|
||||
|
||||
def play(fname, **kwargs):
|
||||
return launch('aplay', fname, '-q', '-f', audio_format, '-c', '1', '-r', Fs, **kwargs)
|
||||
args = ['aplay', fname, '-q', '-f', audio_format, '-c', '1', '-r', Fs]
|
||||
return launch(*args, **kwargs)
|
||||
|
||||
|
||||
def record(fname, **kwargs):
|
||||
return launch('arecord', fname, '-q', '-f', audio_format, '-c', '1', '-r', Fs, **kwargs)
|
||||
args = ['arecord', fname, '-q', '-f', audio_format, '-c', '1', '-r', Fs]
|
||||
return launch(*args, **kwargs)
|
||||
|
||||
|
||||
def launch(*args, **kwargs):
|
||||
args = map(str, args)
|
||||
@@ -34,11 +39,15 @@ if __name__ == '__main__':
|
||||
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.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.add_argument(
|
||||
'filename', default='-',
|
||||
help='path to the audio file to play (otherwise, use stdin)')
|
||||
player.set_defaults(func=play)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
Reference in New Issue
Block a user