1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- # 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 = 150
-
- # 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
- # Play a 400hz beep sound
- (New-Object Media.SoundPlayer -ArgumentList "C:\Windows\Media\Windows Notify.wav").PlaySync()
- $audioFile = "$env:userprofile\AudioTest.wav"
- $audioFile = $audioFile.Replace("\\","\")
- $audioFile = $audioFile.Replace("/","\")
- $audioFile = [System.IO.Path]::GetFullPath($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
- $rec = New-Object System.Media.SoundPlayer
- $rec.SoundLocation = $audioFile
- $rec.Open()
- $rec.Play()
- })
- $form.Controls.Add($recordButton)
-
- # Create the Stop Recording button
- $stopButton = New-Object System.Windows.Forms.Button
- $stopButton.Text = "Stop Recording"
- $stopButton.Width = 75
- $stopButton.Height = 25
- $stopButton.Location = New-Object System.Drawing.Point(100,10)
- $stopButton.Add_Click({
- # Code to run when the Stop Recording button is clicked
- # Play a 400hz beep sound
- (New-Object Media.SoundPlayer -ArgumentList "C:\Windows\Media\Windows Notify.wav").PlaySync()
- $rec.Stop()
- $rec.Dispose()
- })
- $form.Controls.Add($stopButton)
-
- # 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(190,10)
- $playbackButton.Add_Click({
- # Code to run when the Playback button is clicked
- # Play a 400hz beep sound
- (New-Object Media.SoundPlayer -ArgumentList "C:\Windows\Media\Windows Notify.wav").PlaySync()
- $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(10,50)
- $cleanupButton.Add_Click({
- # Code to run when the Cleanup button is clicked
- # Play a 400hz beep sound
- (New-Object Media.SoundPlayer -ArgumentList "C:\Windows\Media\Windows Notify.wav").PlaySync()
- $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
|