Morse code
It has been in use for more than 175 years — longer than any other electronic encoding system.



Task

Send a string as audible Morse code to an audio device   (e.g., the PC speaker).



As the standard Morse code does not contain all possible characters,
you may either ignore unknown characters in the file,
or indicate them somehow   (e.g. with a different pitch).




'The following code relies on the Windows API
Input "Input the text to translate to Morse Code... "; string$
Print PlayMorse$(string$)
End
 
Function PlayMorse$(string$)
    'LetterGap = (3 * BaseTime)
    'WordGap = (7 * BaseTime)
    BaseTime = 50
    freq = 1250
    PlayMorse$ = TranslateToMorse$(string$)
    morseCode$ = "./-"
    For i = 1 To Len(PlayMorse$)
        Scan
        dwDuration = (Instr(morseCode$, Mid$(PlayMorse$, i, 1)) * BaseTime)
        If (Mid$(PlayMorse$, i, 1) <> " ") Then
            CallDLL #kernel32, "Beep", freq As ulong, dwDuration As ulong, ret As long
            CallDLL #kernel32, "Sleep", BaseTime As long, ret As void
        End If
        If (Mid$(PlayMorse$, i, 1) <> " ") Then
            sleep = (3 * BaseTime)
        Else
            sleep = (7 * BaseTime)
        End If
        CallDLL #kernel32, "Sleep", sleep As long, ret As void
    Next i
End Function
 
Function TranslateToMorse$(string$)
    string$ = Upper$(string$)
    For i = 1 To Len(string$)
        While desc$ <> "End"
            Read desc$, value$
            If desc$ = "" Then desc$ = chr$(34)
            If desc$ = Mid$(string$, i, 1) Then
                If Mid$(string$, i, 1) <> " " Then value$ = " " + value$
                TranslateToMorse$ = TranslateToMorse$ + value$
                Exit While
            End If
        Wend
        If desc$ = "End" Then Notice Mid$(string$, i, 1) + " is not accounted for in the Morse Code Table."
        Restore
    Next i
    TranslateToMorse$ = Trim$(TranslateToMorse$)
    Data "A", ".-", "B", "-...", "C", "-.-.", "D", "-..", "E", ".", "F", "..-.", "G", "--."
    Data "H", "....", "I", "..", "J", ".---", "K", "-.-", "L", ".-..", "M", "--", "N", "-."
    Data "O", "---", "P", ".--.", "Q", "--.-", "R", ".-.", "S", "...", "T", "-", "U", "..-"
    Data "V", "...-", "W", ".--", "X", "-..-", "Y", "-.--", "Z", "--..", "Á", "--.-", "Ä", ".-.-"
    Data "É", "..-..", "Ñ", "--.--", "Ö", "---.", "Ü", "..--", "1", ".----", "2", "..---"
    Data "3", "...--", "4", "....-", "5", ".....", "6", "-....", "7", "--...", "8", "---.."
    Data "9", "----.", "0", "-----", ",", "--..--", ".", ".-.-.-", "?", "..--..", ";", "-.-.-"
    Data ":", "---...", "/", "-..-.", "-", "-....-", "'", ".----.", "+", ".-.-.", "", ".-..-."
    Data "@", ".--.-.", "(", "-.--.", ")", "-.--.-", "_", "..--.-", "$", "...-..-", "&", ".-..."
    Data "=", "-...-", "!", "..--.", " ", " ", "End", ""
End Function 