# Bypass execution policy if (!(Test-Path -Path "$env:windir\system32\WindowsPowerShell\v1.0\powershell.exe")) { # PowerShell 2.0 and below Set-ExecutionPolicy Bypass -Scope Process } else { # PowerShell 3.0 and above powershell.exe -ExecutionPolicy Bypass -Command "&{}" } # Import the System.Windows.Forms assembly Add-Type -AssemblyName System.Windows.Forms # Create the GUI form $form = New-Object System.Windows.Forms.Form $form.Text = "EF Audio Tester" $form.Width = 300 $form.Height = 100 # Create the Record button $recordButton = New-Object System.Windows.Forms.Button $recordButton.Text = "Record" $recordButton.Width = 75 $recordButton.Height = 25 $recordButton.Location = New-Object System.Drawing.Point(10,10) $recordButton.Add_Click({ # Code to run when the Record button is clicked $audioFile = "$env:userprofile\AudioTest.wav" $audioFile = $audioFile.Replace("\\","\") $audioFile = $audioFile.Replace("/","\") $audioFile = [System.IO.Path]::GetFullPath($audioFile) $audioFile $audioFile | Add-Member -MemberType NoteProperty -Name Attributes -Value ([System.IO.FileAttributes]::Hidden) # Record audio from the default audio recording device into the temporary file Start-Process -FilePath "ms-settings:sound" -ArgumentList "-microphone" Start-Sleep -s 5 $rec = New-Object -ComObject SAPI.SpVoice $rec.Voice = $rec.GetVoices().Item(0) $rec.speak("Recording started.") $rec.AudioOutputStream = (New-Object -ComObject SAPI.SpFileStream) $rec.AudioOutputStream.Open($audioFile,3) $rec.Speak("Recording.") Start-Sleep -s 10 $rec.speak("Recording stopped.") $rec.AudioOutputStream.Close() $rec.AudioOutputStream = $null $rec = $null $rec.speak("Recording has been saved.") }) $form.Controls.Add($recordButton) # Create the Playback button $playbackButton = New-Object System.Windows.Forms.Button $playbackButton.Text = "Playback" $playbackButton.Width = 75 $playbackButton.Height = 25 $playbackButton.Location = New-Object System.Drawing.Point(100,10) $playbackButton.Add_Click({ # Code to run when the Playback button is clicked $audioFile = "$env:userprofile\AudioTest.wav" $audioFile = $audioFile.Replace("\\","\") $audioFile = $audioFile.Replace("/","\") $audioFile = [System.IO.Path]::GetFullPath($audioFile) # Play the temporary file (New-Object Media.SoundPlayer -ArgumentList $audioFile).PlaySync() }) $form.Controls.Add($playbackButton) # Create the Cleanup button $cleanupButton = New-Object System.Windows.Forms.Button $cleanupButton.Text = "Cleanup" $cleanupButton.Width = 75 $cleanupButton.Height = 25 $cleanupButton.Location = New-Object System.Drawing.Point(190,10) $cleanupButton.Add_Click({ # Code to run when the Cleanup button is clicked $audioFile = "$env:userprofile\AudioTest.wav" $audioFile = $audioFile.Replace("\\","\") $audioFile = $audioFile.Replace("/","\") $audioFile = [System.IO.Path]::GetFullPath($audioFile) # Delete the temporary file Remove-Item $audioFile -Force # Display a message indicating that the file has been deleted [System.Windows.Forms.MessageBox]::Show("AudioTest.wav has been deleted.") }) $form.Controls.Add($cleanupButton) # Show the GUI form $form.ShowDialog() | Out-Null