以下、サンプル
#無くても良いが名前空間の記述を省略できるので使用する
using namespace Microsoft.VisualBasic
#全角⇒半角の変換にVB.NETの機能を使用するため
Add-Type -AssemblyName Microsoft.VisualBasic
$frequency=800 #音の周波数
$ton=100 #短点の長さ
$too=300 #長点の長さ
$HashTable = @{
"A"="$ton,$too"
"B"="$too,$ton,$ton,$ton"
"C"="$too,$ton,$too,$ton"
"D"="$too,$ton,$ton"
"E"="$ton"
"F"="$ton,$ton,$too,$ton"
"G"="$too,$too,$ton"
"H"="$ton,$ton,$ton,$ton"
"I"="$ton,$ton"
"J"="$ton,$too,$too,$too"
"K"="$too,$ton,$too"
"L"="$ton,$too,$ton,$ton"
"M"="$too,$too"
"N"="$too,$ton"
"O"="$too,$too,$too"
"P"="$ton,$too,$too,$ton"
"Q"="$too,$too,$ton,$too"
"R"="$ton,$too,$ton"
"S"="$ton,$ton,$ton"
"T"="$too"
"U"="$ton,$ton,$too"
"V"="$ton,$ton,$ton,$too"
"W"="$ton,$too,$too"
"X"="$too,$ton,$ton,$too"
"Y"="$too,$ton,$too,$too"
"Z"="$too,$too,$ton,$ton"
"1"="$ton,$too,$too,$too,$too"
"2"="$ton,$ton,$too,$too,$too"
"3"="$ton,$ton,$ton,$too,$too"
"4"="$ton,$ton,$ton,$ton,$too"
"5"="$ton,$ton,$ton,$ton,$ton"
"6"="$too,$ton,$ton,$ton,$ton"
"7"="$too,$too,$ton,$ton,$ton"
"8"="$too,$too,$too,$ton,$ton"
"9"="$too,$too,$too,$too,$ton"
"0"="$too,$too,$too,$too,$too"
}
Write-Host "何か入力して下さい。"
[console]::Beep(37,1)
$str=Read-Host
# 全角を半角へ変換と小文字を大文字に変換
$str = [Strings]::StrConv($str,[VbStrConv]::Narrow)
$str = $str.toupper()
#Beep音を鳴らす
foreach ($item in $str.ToCharArray()){
$item
if ($item -ne " "){
foreach($morse in $HashTable[$item.ToString()].split(",")){
[console]::Beep($frequency,$morse)
}
Start-Sleep -m ($ton * 3)
} else {
Start-Sleep -m ($ton * 7)
}
}
[console]::Beep(37,1)
について
本来必要ないが、ループ処理時に最初の音だけ鳴らないことがあったため、処理の初めに聞こえない音を一瞬鳴らしておくことで対処。