Guru A virtual teacher who reveals to you the great secrets of Base64 Then stringToMorse xs ++ "Writing to morse-out.Base64. Pid <- runCommand "aplay -q morse-out.wav" PutAudioToString f = audioToString f >= putStrLn PutAudioToMorse f = audioToMorse f >= putStrLn Take audio into morse code and print itĭo (WAVE _ ws) if abs (x - d) if abs (x - d) IO () map (\x -> (x`div`dampingFactor)*dampingFactor)ĪudioToSamples :: WAVESamples -> ĪudioToSamples ws = tidyZ $ groupZ False 0 $ concat ws morse, but will probably break on morse by human beings. between dits and dahs in a letter, which ought to work for automatically generated and assuming that the most frequently occuring of these will be the gap We use this by taking a list of lengths of spaces (from getSpaceLengths) Utility function, find the most frequently occuring thing in a list Given a list of Beeps and Spaces, return a list of the durations of the spaces (Beep i, Beep j) -> tidyZ ((Beep (i+j)):xs) Then (groupZ False 1 (drop (spaces+1) xs))Įlse (Beep (beeps+1+count)) : (groupZ True 0 (drop (beeps+1) xs))īeeps = length $ takeWhile (not. Then (Space (spaces+1)) : (groupZ False 0 (drop (spaces+1) xs)) Listening to audio and translating to morse or stringsĭata Sample a = Space a | Beep a deriving Show MakeWavFile xs = putWAVEFile "morse-out.wav" (WAVE header xs) StringToMorseSounds xs = map charToMorseSound $ stringToMorse xs StringToMorseSounds :: String -> WAVESamples StringToMorseWavFile xs = makeWavFile $ concatMap (map (:)) $ stringToMorseSounds xs MedSpace = sound 0 samplesPS (morseSpeed * 0.5) 0ĭit = sound beepFreq samplesPS (morseSpeed * 0.25) (maxBound `div` 2)ĭah = sound beepFreq samplesPS (morseSpeed * 0.75) (maxBound `div` 2) LongSpace = sound 0 samplesPS (morseSpeed * 1.25) 0 Space = sound 0 samplesPS (morseSpeed * 0.25) 0 ![]() Take (round $ len * (fromIntegral samples)) $ > Int32 - | Volume, (maxBound :: Int32) for highest, 0 for lowest Header = WAVEHeader 1 samplesPS bitrate Nothing = 3 - higher is slower, could make this into a commandline option ![]() Header = "Usage: morse (y,x)) $ M.toList lettersīeepFreq = 800 - dits and dahs come out at this frequency (_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options)) (o,n, ) -> return (foldl (flip id) defaultOptions o, n) Import Data.List (intersperse, groupBy, group)ĭata Options = Options )) "Go on about it at great length" Import qualified Data.Map as M (Map, toList, fromList, lookup) Here is the final code The final morse.hs code If you want the code, please take and improve. I’ve had great fun this week making my computer beep and I have learned a fair amount from making morse.hs. Will try and get a better set up for the next screencast! My microphone is a bit crap though, so the sound is far from great. Incidentaly vokoscreen is a pretty nice bit of screencasting software for GNU/Linux. ![]() Sorry, but you just wouldn't upload my file! Plus because I am putting it on yt, I can be as long-winded as I like talking through the code and save myself editing time. Thanks for the Neat! Now, what about translating an audio signal?- Russell Banned May 27, 2014įortunately, I finally found something that worked for doing screencasts. The idea of translating audio back into something more human-friendly was suggested by when I put up my Let’s make morse code with Haskell blog post. Today is the final installment in my Haskell morse code odyssey, in which I translate some audio of morse code back into dots and dahs and even strings on the screen.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |