#---8<---gadget-morse.ps1---Jean-JMST-Belgium---8<--- #=10/2006==================================Version 0==========# #================ plays a string in Morse ==================# # # *This script needs script gadget-piano.ps1 in its directory # to work properly* # # To use : # # -text paremeter is a string containing the string to play. # # -dit paremeter is the duration in milliseconds of a "dit" # default=60 # # -note paremeter is the (string) note used to play "dit" and # "dah" Morse sounds # default=3A # # -verbose switch writes words and Morse code in console. # # To test : # # .\gadget-morse # °plays a demo string # .\gadget-morse -verbose # °plays a demo string and outputs words and Morse code # .\gadget-morse "Hello world" -verbose # °plays "Hello world" in Morse and outputs words and code # .\gadget-morse "Hello world" 70 "1G" # °plays "Hello world" with a Dit length of 70 ms and a G # note to play Dit and Dah # # gadget-morse.ps1 is a demo script reusing this one # # NOTE : # # You must have a pc internal speaker present and enabled # to hear something :-) # #========Tested on PowerShell 1 RC2===========================# param( [string]$text='PowerShell is powerful', [int32]$dit=60, [string]$note='3A', [switch]$verbose ) filter play-morse{ [char[]]$_|%{ switch([string]$_){ - { .\gadget-piano $note ($dit*3) $dit break } ° { .\gadget-piano $note $dit $dit break } } } }#end filter play-morse $chars="abcdefghijklmnopqrstuvwxyz0123456789"+ ".,?-äàéèöü`"!'/ñþç@`$:;=()" $morse='°-','-°°°','-°-°','-°°','°','°°-°','--°', '°°°°','°°','°---','-°-','°-°°','--','-°', '---','°--°','--°-','°-°','°°°','-','°°-', '°°°-','°--','-°°-','-°--','--°°','-----', '°----','°°---','°°°--','°°°°-','°°°°°', '-°°°°','--°°°','---°°','----°','°-°-°-', '--°°--','°°--°°','-°°°°-','°-°-','°--°-', '°°-°°','°-°°-','---°','°°--','°-°°-°', '°°--°','°----°','-°°-°','--°--','°--°°', '-°-°°','°--°-°','°°°-°°-','---°°°','-°-°-°', '-°°°-','-°--°-','-°--°-' $h=@{} if($chars.Length -ne $morse.Length){'LIST ERROR';exit} for($i=0;$i -lt $chars.Length;$i++) {$h.Add([string]$chars[$i],$morse[$i])} $text.split()|%{ if($verbose){"<$_>"} [char[]]$_|%{ if($verbose){$h[[string]$_]} $h[[string]$_]|play-morse .\gadget-piano 'Z' ($dit*2) 0 } if($verbose){""} .\gadget-piano 'Z' ($dit*4) 0 } #---8<---gadget-morse.ps1---Jean-JMST-Belgium---8<---