r/dailyprogrammer • • Aug 27 '14
[8/27/2014] Challenge #177 [Intermediate] .- ..- -.. .. ---
Description
Morse code is an aural method of transmitting text through the use of silence and tones.
Todays challenge will involve translating your standard english text into morse code, and from there, into an audio file.
Example
Step 1: "I like cats" - The phrase entered by you for translating
Step 2: .. / .-.. .. -.- . / -.-. .- - ... - The output of the phrase in step 1
Step 3: cats.wav - An audio file containing each dot(.) and dash(-) as an audible tone
Formal Inputs & Outputs
Input description
On standard console input, you should enter a phrase of your choosing. This will then be parsed into morse code and finally outputted as stated in the output description.
Output description
The program should output a valid audio file (WAV, MP3, OGG, as long as it can play it's fine). In that audio should be an audio translation of your input.
Finally
Thanks to /u/13467 for this submission
We're always on the IRC channel on Freenode . Our channel is #reddit-dailyprogrammer
There's usually ~20 or so people on at any given moment, stop by!
Have a good challenge idea?
Consider submitting it to /r/dailyprogrammer_ideas
3
u/adrian17 1 4 Aug 27 '14 edited Aug 28 '14
C++. Considering I've never worked with audio files, I think it went pretty good. I've found the WAV header writer by googling. Only supports letters since I was more concerned with the audio part.
Instead of an audio file (which I have no idea where to host), have an Audacity screenshot: https://i.imgur.com/xT7aU6q.png?1
(not sure why it thinks it's 32-bit)
17
u/skeeto -9 8 Aug 27 '14 edited Aug 27 '14
C, without any libraries. Man this was a fun one! It outputs AU files, since that's probably the simplest audio format that anything supports.
It generates a 1kHz tone from
sin(). The first part of the program makes a tiny tone generating library and the rest uses it to emit morse code.Sample output audio of "daily programmer": MP3, OGG
There's a lot of IO locking going on, and it would be faster using /u/duetosymmetry's lock technique.
Usage:
11
u/Godspiral 3 3 Aug 27 '14 edited Aug 27 '14
A table for those this helps:
Not doing .wav files, but to give others ideas, turning morse code into polka/techno music based on a 12 beat bar signature. (numbers, 5 bits per number, could be implemented with silence on beat 11)
with above table on clipboard, getting binary table:
MCTb =: '.-'&i. each MCT dlb each {: &> '|'&cut @:dltb each cutLF wd 'clippaste'
encoder:
better version that can be pasted into text to speech app: http://www.readspeaker.com/voice-demo/
1
u/bjacks14 Aug 29 '14
Can anyone link to a good tutorial for writing audio files? Any format. Or an easy to use library. Writing binary files is something I've never done and I can't find any tutorial that I can follow. As far as this project though, I've created a program that takes in the input and outputs 0's and 1's to simulate sound-on and sound-off. It would seem simple enough to translate into a sound file.
3
u/stannedelchev Aug 27 '14
Here's mine in C#, couple of files so a github repo is in place :) I'm using NAudio for the WAV output.
3
u/ben_jl Aug 28 '14 edited Aug 28 '14
Solution in J using wav add-on. I just started learning the language a couple days ago, so any advice is appreciated; this was a fun challenge to test a few skills.
3
u/DroidLogician Aug 28 '14 edited Aug 28 '14
Rust, with thanks to /u/skeeto for his AU format idea and pulse generator. It would have taken me a few more hours to figure that part out otherwise.
Usage:
Edit: Forgot what comes after 'w'.
3
u/lukz 2 0 Aug 28 '14
Common Lisp
Reads a line of text from standard input. Then it converts the text into morse code (only letters A-Z are supported). Then it creates a MIDI file with the sound.
The midi file structure is the following:
.
3
u/joyeusenoelle Aug 28 '14 edited Aug 28 '14
Terribly clumsy - but functioning - Python 3:
Output for "I like cats" in WAV format
ht: Nemeth on StackOverflow for demonstrating how to use the wave module
2
u/LearningPythons Aug 28 '14
well, this is my first submission to the daily programmer, but it's not the complete assignment. It translates to morse code and plays on windows machines, but doesn't write the sound file to disk. I'd certainly appreciate feedback as I'm new to this Python thing.
thanks!
2
u/MaximaxII Aug 28 '14 edited Aug 28 '14
A Python solution. I'm really annoyed at how slow the wave module is, but lowering the framerate significantly speedens the whole process up. It follows the official morse standards for the length of dots, dashes and pauses between characters and words.
Here are a few results:
Challenge #171 - Python 2.7
1
u/wadehn Aug 28 '14 edited Aug 28 '14
C++: Outputs wave format as described in https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ without any libraries. Uses correct symbol, letter and word spaces and prints the whole file at once. Plays dots on the left channel and dashes on the right, just cause.
Edit: Output with correct endianness and added packed attribute
The morse code is read from the following file:
1
u/Murken Aug 28 '14 edited Aug 28 '14
Late to the party, but looking for criticism! Python
*Created tones
1
u/andre_nho Aug 29 '14
My solution in Scheme (using Guile):
1
u/bstpierre777 Sep 02 '14
It's a really late submission but I just got around to working the kinks out of the audio. (h/t to skeeto for the AU file idea.)
I'm new to ocaml so any feedback is appreciated.
1
u/thinksInCode Aug 28 '14
I did this one using the Web Audio API. I think it will only work in WebKit browsers.
You can run it here: http://codepen.io/anon/pen/hqJvL
Just type a message, and click Translate to see the Morse code. Then click Listen to hear it!
index.html:
morse.js:
1
u/datgohan Aug 30 '14
Java. I've written the first part to translate input into morse code. Struggling with the audio part now.
0
u/xraystyle Aug 28 '14
Here's the Morse translation portion in Ruby:
Usage: Save the script, run it. It prompts you for text, outputs the Morse translation.
Not sure about the audio, never messed with trying to build an audio file with Ruby. I'll do some googling tomorrow, see what I can come up with.
0
u/MrP_123 Aug 29 '14 edited Aug 29 '14
Here is my submission in plain Java.
https://gist.github.com/MrP123/a0eef7f59cbfa43038fd
It saves a *.wav file to your desktop. My debug methodes to play the sound via code are also still there.
Here is a Audacity screenshot as prove (the word "Test"):
http://i.imgur.com/kU0wzMT.png
0
u/[deleted] Aug 28 '14
[deleted] — view deleted comment