main.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/python3
  2. import glob
  3. from pydub import AudioSegment
  4. import subprocess
  5. baudot = {'Q':[1,1,1,0,1], 'W':[1,0,0,1,1], 'E':[1,0,0,0,0],
  6. 'R':[0,1,0,1,0], 'T':[1,0,0,0,0], 'Y':[1,0,1,0,1],
  7. 'U':[0,0,1,1,1], 'I':[0,0,1,1,0], 'O':[1,1,0,0,0],
  8. 'P':[0,1,1,0,1], 'A':[0,0,0,1,1], 'S':[1,0,1,0,0],
  9. 'D':[1,0,0,1,0], 'F':[0,1,1,0,1], 'G':[1,1,0,1,0],
  10. 'H':[1,0,1,0,0], 'J':[0,1,0,1,1], 'K':[0,1,1,1,1],
  11. 'L':[0,1,0,0,1], 'Z':[1,0,0,0,1], 'X':[1,1,1,0,1],
  12. 'C':[0,1,1,1,0], 'V':[0,1,1,1,1], 'B':[1,1,0,0,1],
  13. 'N':[0,1,1,0,0], 'M':[1,1,1,0,0]}
  14. space = [0,0,1,0,0]
  15. # Message to be sent
  16. message="FIYQ"
  17. if __name__ == "__main__":
  18. import argparse
  19. parser = argparse.ArgumentParser(description="Simple RTTY wav exporter")
  20. parser.add_argument("-c", "--clips", nargs="+", help="This is your message to send")
  21. args = parser.parse_args()
  22. generatedFile = "output.wav"
  23. filenames = glob.glob("*.wav")
  24. stop_bit = AudioSegment.from_wav("stop_bit.wav")
  25. space = AudioSegment.from_wav("space.wav")
  26. wait_state = AudioSegment.from_wav("wait_state.wav")
  27. mark = AudioSegment.from_wav("mark.wav")
  28. combined = AudioSegment.empty()
  29. output_wav = [wait_state]
  30. print(message)
  31. for k in message:
  32. # Recognize white spaces
  33. if ord(k) == 32:
  34. a = space
  35. else:
  36. a = baudot.setdefault(k)
  37. b = len(a)
  38. # Start Bit
  39. output_wav.extend([space])
  40. for i in a:
  41. if i == 1:
  42. output_wav.extend([mark])
  43. elif i == 0:
  44. output_wav.extend([space])
  45. else:
  46. break;
  47. output_wav.extend([stop_bit])
  48. for fname in output_wav:
  49. combined += fname
  50. combined.export(generatedFile, format="wav")
  51. subprocess.call(["aplay", "output.wav"])
  52. subprocess.call(["rm", "-rf", "output.wav"])