暂无描述

ChatGPT-AudioTester.ps1 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Bypass execution policy
  2. if (!(Test-Path -Path "$env:windir\system32\WindowsPowerShell\v1.0\powershell.exe")) {
  3. # PowerShell 2.0 and below
  4. Set-ExecutionPolicy Bypass -Scope Process
  5. } else {
  6. # PowerShell 3.0 and above
  7. powershell.exe -ExecutionPolicy Bypass -Command "&{}"
  8. }
  9. # Import the System.Windows.Forms assembly
  10. Add-Type -AssemblyName System.Windows.Forms
  11. # Create the GUI form
  12. $form = New-Object System.Windows.Forms.Form
  13. $form.Text = "EF Audio Tester"
  14. $form.Width = 300
  15. $form.Height = 100
  16. # Create the Record button
  17. $recordButton = New-Object System.Windows.Forms.Button
  18. $recordButton.Text = "Record"
  19. $recordButton.Width = 75
  20. $recordButton.Height = 25
  21. $recordButton.Location = New-Object System.Drawing.Point(10,10)
  22. $recordButton.Add_Click({
  23. # Code to run when the Record button is clicked
  24. $audioFile = "$env:userprofile\AudioTest.wav"
  25. $audioFile = $audioFile.Replace("\\","\")
  26. $audioFile = $audioFile.Replace("/","\")
  27. $audioFile = [System.IO.Path]::GetFullPath($audioFile)
  28. $audioFile
  29. $audioFile | Add-Member -MemberType NoteProperty -Name Attributes -Value ([System.IO.FileAttributes]::Hidden)
  30. # Record audio from the default audio recording device into the temporary file
  31. Start-Process -FilePath "ms-settings:sound" -ArgumentList "-microphone"
  32. Start-Sleep -s 5
  33. $rec = New-Object -ComObject SAPI.SpVoice
  34. $rec.Voice = $rec.GetVoices().Item(0)
  35. $rec.speak("Recording started.")
  36. $rec.AudioOutputStream = (New-Object -ComObject SAPI.SpFileStream)
  37. $rec.AudioOutputStream.Open($audioFile,3)
  38. $rec.Speak("Recording.")
  39. Start-Sleep -s 10
  40. $rec.speak("Recording stopped.")
  41. $rec.AudioOutputStream.Close()
  42. $rec.AudioOutputStream = $null
  43. $rec = $null
  44. $rec.speak("Recording has been saved.")
  45. })
  46. $form.Controls.Add($recordButton)
  47. # Create the Playback button
  48. $playbackButton = New-Object System.Windows.Forms.Button
  49. $playbackButton.Text = "Playback"
  50. $playbackButton.Width = 75
  51. $playbackButton.Height = 25
  52. $playbackButton.Location = New-Object System.Drawing.Point(100,10)
  53. $playbackButton.Add_Click({
  54. # Code to run when the Playback button is clicked
  55. $audioFile = "$env:userprofile\AudioTest.wav"
  56. $audioFile = $audioFile.Replace("\\","\")
  57. $audioFile = $audioFile.Replace("/","\")
  58. $audioFile = [System.IO.Path]::GetFullPath($audioFile)
  59. # Play the temporary file
  60. (New-Object Media.SoundPlayer -ArgumentList $audioFile).PlaySync()
  61. })
  62. $form.Controls.Add($playbackButton)
  63. # Create the Cleanup button
  64. $cleanupButton = New-Object System.Windows.Forms.Button
  65. $cleanupButton.Text = "Cleanup"
  66. $cleanupButton.Width = 75
  67. $cleanupButton.Height = 25
  68. $cleanupButton.Location = New-Object System.Drawing.Point(190,10)
  69. $cleanupButton.Add_Click({
  70. # Code to run when the Cleanup button is clicked
  71. $audioFile = "$env:userprofile\AudioTest.wav"
  72. $audioFile = $audioFile.Replace("\\","\")
  73. $audioFile = $audioFile.Replace("/","\")
  74. $audioFile = [System.IO.Path]::GetFullPath($audioFile)
  75. # Delete the temporary file
  76. Remove-Item $audioFile -Force
  77. # Display a message indicating that the file has been deleted
  78. [System.Windows.Forms.MessageBox]::Show("AudioTest.wav has been deleted.")
  79. })
  80. $form.Controls.Add($cleanupButton)
  81. # Show the GUI form
  82. $form.ShowDialog() | Out-Null

Powered by TurnKey Linux.