12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #!/bin/python3
- import glob
- from pydub import AudioSegment
- import subprocess
- baudot = {'Q':[1,1,1,0,1], 'W':[1,0,0,1,1], 'E':[1,0,0,0,0],
- 'R':[0,1,0,1,0], 'T':[1,0,0,0,0], 'Y':[1,0,1,0,1],
- 'U':[0,0,1,1,1], 'I':[0,0,1,1,0], 'O':[1,1,0,0,0],
- 'P':[0,1,1,0,1], 'A':[0,0,0,1,1], 'S':[1,0,1,0,0],
- 'D':[1,0,0,1,0], 'F':[0,1,1,0,1], 'G':[1,1,0,1,0],
- 'H':[1,0,1,0,0], 'J':[0,1,0,1,1], 'K':[0,1,1,1,1],
- 'L':[0,1,0,0,1], 'Z':[1,0,0,0,1], 'X':[1,1,1,0,1],
- 'C':[0,1,1,1,0], 'V':[0,1,1,1,1], 'B':[1,1,0,0,1],
- 'N':[0,1,1,0,0], 'M':[1,1,1,0,0]}
- space = [0,0,1,0,0]
- # Message to be sent
- message="FIYQ"
- if __name__ == "__main__":
- import argparse
- parser = argparse.ArgumentParser(description="Simple RTTY wav exporter")
- parser.add_argument("-c", "--clips", nargs="+", help="This is your message to send")
- args = parser.parse_args()
- generatedFile = "output.wav"
- filenames = glob.glob("*.wav")
- stop_bit = AudioSegment.from_wav("stop_bit.wav")
- space = AudioSegment.from_wav("space.wav")
- wait_state = AudioSegment.from_wav("wait_state.wav")
- mark = AudioSegment.from_wav("mark.wav")
- combined = AudioSegment.empty()
- output_wav = [wait_state]
- print(message)
- for k in message:
- # Recognize white spaces
- if ord(k) == 32:
- a = space
- else:
- a = baudot.setdefault(k)
- b = len(a)
- # Start Bit
- output_wav.extend([space])
- for i in a:
- if i == 1:
- output_wav.extend([mark])
- elif i == 0:
- output_wav.extend([space])
- else:
- break;
- output_wav.extend([stop_bit])
- for fname in output_wav:
- combined += fname
- combined.export(generatedFile, format="wav")
- subprocess.call(["aplay", "output.wav"])
- subprocess.call(["rm", "-rf", "output.wav"])
|