似乎几乎所有东西都有 Web Service。这是一个将文本转换为摩尔斯电码的 Web Service:
1 2 3 4 5 6 7 8 9 10 11
| $Text = 'SOS This is an emergency!'
Add-Type -AssemblyName System.Web $encoded = [System.Web.HttpUtility]::UrlEncode($Text)
$Url = "https://api.funtranslations.com/translate/morse.json?text=$encoded"
(Invoke-RestMethod -UseBasicParsing -Uri $url).contents.translated
|
结果看起来像这样:
... --- ... - .... .. ... .. ... .- -. . -- . .-. --. . -. -.-. -.-- ---.
如果您确实对摩尔斯电码有兴趣,请解析结果文本并创建真正的哔哔声:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| $Text = 'Happy New Year 2021!'
Add-Type -AssemblyName System.Web $encoded = [System.Web.HttpUtility]::UrlEncode($Text)
$Url = "https://api.funtranslations.com/translate/morse.json?text=$encoded"
$morse = (Invoke-RestMethod -UseBasicParsing -Uri $url).contents.translated
Foreach ($char in $morse.ToCharArray()) { switch ($char) { '.' { [Console]::Beep(800, 300) } '-' { [Console]::Beep(800, 900) } ' ' { Start-Sleep -Milliseconds 500 } default { Write-Warning "Unknown char: $_" [Console]::Beep(2000, 500) }
} Write-Host $char -NoNewline Start-Sleep -Milliseconds 200 } Write-Host "OK"
|