Переглянути джерело

Add 'ChatGPT-AudioTester.ps1'

Ethan 2 роки тому
джерело
коміт
52e3f5f437
1 змінених файлів з 88 додано та 0 видалено
  1. 88
    0
      ChatGPT-AudioTester.ps1

+ 88
- 0
ChatGPT-AudioTester.ps1 Переглянути файл

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

Powered by TurnKey Linux.