Skip to content

Update to allow the output file to have a different sample rate #4

@minghia

Description

@minghia

I wanted to have a 16000 kHz sample rate so I modified play.py so that it can take a different sample rate if the -r flag is used. Use if you want:
diff --git a/play.py b/play.py
index b622d50..3db736d 100755
--- a/play.py
+++ b/play.py
@@ -18,13 +18,13 @@ AUDIO_PADDING = 0.5 # Seconds
CLICK_SMOOTH = 2 # Tone periods

-def main(message, freq, wpm, fs, prompt, outFile):
+def main(message, freq, wpm, fs, rate, prompt, outFile):
if prompt:
# Load spoken letter WAV files
letterNames = loadLetterNames()
sps = letterNames[LETTERS[0]][0]
else:

  • sps = SPS
  • sps = rate
    print('Audio samples per second =', sps)
    print('Tone period =', round(1000/freq, 1), 'ms')

@@ -138,6 +138,7 @@ if name == 'main':
parser.add_argument('--fs', type=float, default=FS, help='Farnsworth speed')
parser.add_argument('-p', action='store_true', default=False, help='Say letters along with morse code')
parser.add_argument('-o', type=str, default='', help='Output to given WAV file instead of playing sound')

  • parser.add_argument('-r', type=int, default=SPS, help='Sample Rate')
    parser.add_argument('message', nargs='*', help='Text to translate or blank to take from stdin')
    args = parser.parse_args()

@@ -149,5 +150,5 @@ if name == 'main':
if not message:
print('Specify a message through the command line or stdin.')
message = 'Specify a message.'

  • main(message, args.f, args.wpm, args.fs, args.p, args.o)
  • main(message, args.f, args.wpm, args.fs, args.r, args.p, args.o)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions