Created
August 28, 2025 19:08
-
-
Save markjenkins/d2a594f934b774225d2714dc85e07ddf to your computer and use it in GitHub Desktop.
WPM estimation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # calculate the WPM of a dit ".", dah "-", space (intra word) | |
| # and "/" (inter word) string as per the output of | |
| # https://morsecode.world/international/translator.html | |
| # | |
| # provide the number of seconds as an argument | |
| # | |
| # example run | |
| # python3 .\count_dits_est_wpm.py 57 | |
| # . ...- . .-. -.-- / -.. .. - / .- -. -.. / -.. .- .... / -.-. .- .-. .-. .. . ... / .- / ...- --- .. -.-. . / .- -.-. .-. --- ... ... / - .... . / .- .. .-. .-- .- ...- . ... .-.-.- | |
| # 7.768421052631578 | |
| # | |
| # Source: | |
| # https://www.youtube.com/watch?v=bON3iRMHZ6s | |
| # "every dit and dah carries a voice across the airwaves." | |
| def count_dits(dit_dah_stroke_str): | |
| s = dit_dah_stroke_str.split("/") | |
| dit_count = sum( 1 if c == "." else (3 if c=="-" else 0) | |
| for b in s | |
| for c in b) | |
| intra_word_spacing_dit_count = sum( | |
| 3 * ( len(b.strip().split(" ")) - 1) | |
| for b in s) | |
| return ( | |
| (len(s)-1) * 7 + # inter word spacing | |
| intra_word_spacing_dit_count + | |
| dit_count ) | |
| def calc_wpm_of_dit_dah_stroke_str(dit_dah_stroke_str, seconds): | |
| dits = count_dits(dit_dah_stroke_str) | |
| # see https://k7mem.com/Keyer_Speed.html | |
| # for the constant 1.2 WPM per seconds per dit | |
| return 1.2/(seconds/dits) | |
| if __name__ == "__main__": | |
| from sys import argv | |
| input_line = input() | |
| print( | |
| calc_wpm_of_dit_dah_stroke_str(input_line, float(argv[1])) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment