Computer Science Canada

Morse code translator

Author:  Insectoid [ Wed Jun 16, 2010 4:47 pm ]
Post subject:  Morse code translator

So, I was bored and made this. There's some messy stuff in it (like the initialization of number sequences) but it works. Feel free to mess around with the 'speed' and 'freq' constants, though you need to stay in the hearing range for freq and any speed under 75 just sounds like a bunch of clicks.

Turing:

var letters : array 1..36 of string
const freq := 500 %frequency of blips
const speed := 75 %blip length modifier
%Boring manual assignment of blip sequences
letters (1) := "13"
letters (2) := "3111"
letters (3) := "3131"
letters (4) := "311"
letters (5) := "1"
letters (6) := "1131"
letters (7) := "331"
letters (8) := "1111"
letters (9) := "11"
letters (10) := "1333"
letters (11) := "313"
letters (12) := "1311"
letters (13) := "33"
letters (14) := "31"
letters (15) := "333"
letters (16) := "1331"
letters (17) := "3313"
letters (18) := "131"
letters (19) := "111"
letters (20) := "3"
letters (21) := "113"
letters (22) := "1113"
letters (23) := "133"
letters (24) := "3113"
letters (25) := "3133"
letters (26) := "3311"
%add 1-9+0 to the list, too lazy to make the computer figure it out.
letters (27) := "33333"
letters (28) := "13333"
letters (29) := "11333"
letters (30) := "11133"
letters (31) := "11113"
letters (32) := "11111"
letters (33) := "31111"
letters (34) := "33111"
letters (35) := "33311"
letters (36) := "33331"


proc tone (seq:string)
    for x: 1..length (seq)
        Music.Sound (freq, speed*strint(seq(x)))
        Music.SoundOff
        delay (round (1.5*speed))
    end for
end tone
loop
put "Enter a sentence to convert: "..
var text : string
get text : *
put "Morse code of \"" + text + "\":"
for x: 1..length (text)
    put text (x)+" "..
    if ord (text(x)) >= 97 and ord(text(x)) <= 122 then
        put letters (ord(text(x))-96)
        tone (letters  (ord(text(x))-96))
    elsif ord (text(x)) >= 65 and ord(text(x)) <= 90 then
        put letters (ord(text(x))-64)
        tone (letters  (ord(text(x))-64))
    elsif strintok (text(x)) then
        put letters (strint (text(x))+26)
        tone (letters (strint (text(x))+ 26))
    elsif text (x) = " " then
        put "<Space>"
        delay (7*speed)
    else
        put "<invalid character>"
    end if
    delay (3*speed)
end for
end loop

Author:  Cezna [ Wed Jun 16, 2010 6:00 pm ]
Post subject:  RE:Morse code translator

Awesome program Insectoid, had a lot of fun messing around with it.

Out of curiosity, why did you use 1's and 3's instead of 1's and 2's or 0's and 1's ?

EDIT: Doohhh !!!
Just realized as I hit submit it must be to control the duration of the beeps....

Author:  Insectoid [ Wed Jun 16, 2010 6:39 pm ]
Post subject:  RE:Morse code translator

I'm meeting the standard. A short beep is 1 unit long, a long beep is 3, pause between letters is 3 units (I think....) and between words is 7.

Author:  Cezna [ Wed Jun 16, 2010 6:43 pm ]
Post subject:  RE:Morse code translator

Is the 7 accurate?
Either way, very cool, great work.

Author:  Insectoid [ Wed Jun 16, 2010 7:53 pm ]
Post subject:  RE:Morse code translator

Yes, the 7 is accurate. What isn't accurate is the space between beeps within individual letters, which should be 1 unit while mine is 1.5. Just worked better.

Author:  Cezna [ Wed Jun 16, 2010 8:17 pm ]
Post subject:  RE:Morse code translator

You made the right choice, because it works great.

Author:  Turing_Gamer [ Thu Aug 19, 2010 2:55 am ]
Post subject:  Re: Morse code translator

Really cool but I think the morse code is a little faster than that. Laughing Anyway, nice program. I always wanted to convey messages in morse code.

Author:  mirhagk [ Thu Aug 19, 2010 8:52 am ]
Post subject:  RE:Morse code translator

no if only it could translate from morse code....

Lol maybe this would go into my free ipod app ideas (the idea being make simple but useful and popular apps, but charge no price, but merely have ads, and then a pro version with no ads.

Author:  Insectoid [ Thu Aug 19, 2010 9:07 am ]
Post subject:  RE:Morse code translator

Turing_Gamer, you can make it as fast as you like by changing the constant speed.

If this were to be a phone app, I'd like it to also convert morse to text, and convert text to morse on-the-fly so you don't have to type out the entire sentence before converting. Of course this then presents the issue of typos and backspace, and people who type slower than morse code can be generated.

Author:  chrisbrown [ Thu Aug 19, 2010 9:20 am ]
Post subject:  Re: RE:Morse code translator

mirhagk @ Thu Aug 19, 2010 8:52 am wrote:
the idea being make simple but useful and popular apps

Sounds like a variation of the <a href="http://en.wikipedia.org/wiki/Project_triangle">Pick 2</a> problem.

(The iFart app comes to mind.. simple and disgustingly popular, but probably the most useless app ever)

Author:  Turing_Gamer [ Tue Aug 24, 2010 1:25 pm ]
Post subject:  RE:Morse code translator

I think the morse to text is way beyond the capability of Turing.

First: You need a fool-proof way of recording Morse. When people contact in Morse, they have their own way of holding the sound. Some go fast while some go slow. So the program need to analyze what is long and what is short and what is a pause.

Second: The sound must be broken up accordingly by pauses, short blips, and long beeps. For this to happen, the code must be further analyzed which far from what Turing can do.

Third: Turing can possibly help with this one. All you have too do is make the 1st one a reference, then match that with the already broken up code, add a little conversion table to tell what beep is what letter and there you go.

In short, if you ever manage to do this with Turing, I commend you.

Author:  DemonWasp [ Tue Aug 24, 2010 2:12 pm ]
Post subject:  RE:Morse code translator

@Turing_Gamer: As Turing is a Turing-complete language, theoretically such a program is possible. It wouldn't be easy, but it'd be quite possible.

Author:  Srlancelot39 [ Tue Sep 14, 2010 3:37 pm ]
Post subject:  RE:Morse code translator

@Turing_Gamer
yeah i cant see it being easy/possible to translate the sound to words, but what if the morse code was entered as text i.e. a 1 represents a tap, a 3 represents a hold, and a " " represents a space.....
then it would be easily possible.
IF I GAVE ANYONE IDEAS, PLEASE GO FORWARD WITH THEM! =D

Author:  Insectoid [ Tue Sep 14, 2010 6:23 pm ]
Post subject:  RE:Morse code translator

Srlancelot39, that would work, but the question remains as to how you get that file of characters in the first place. The idea is that you record a string of blips that represent morse code and convert that to a usable string of characters, ie 0's, 1's and 3's, that can then be converted to text.

If all your program does is translate a bunch of 1's and 3's into text, it isn't translating morse. It's just parsing a very strange text format.

Author:  Srlancelot39 [ Wed Sep 15, 2010 8:18 pm ]
Post subject:  Re: RE:Morse code translator

Insectoid @ Tue Sep 14, 2010 5:23 pm wrote:
Srlancelot39, that would work, but the question remains as to how you get that file of characters in the first place. The idea is that you record a string of blips that represent morse code and convert that to a usable string of characters, ie 0's, 1's and 3's, that can then be converted to text.

If all your program does is translate a bunch of 1's and 3's into text, it isn't translating morse. It's just parsing a very strange text format.

ya it's kinda sad how thats so true...=(.....could still be fun though lol

Author:  mirhagk [ Wed Sep 15, 2010 8:31 pm ]
Post subject:  RE:Morse code translator

@Demon Wasp

It'd be a very, vey interesting concept to try. I don't even know how you'd get the audio file, I've never actually seen any programs that worek with audio, although, I've always been curious about it, maybe I'll get into sound file manipulation.


: