-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.ps1
93 lines (85 loc) · 3.37 KB
/
setup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<#
.SYNOPSIS
Configures Talk2Windows
.DESCRIPTION
This script exports all PowerShell scripts from subfolder 'scripts' as Serenade voice phrases.
.EXAMPLE
PS> ./setup.ps1
.NOTES
Author: Markus Fleschutz / License: CC0
.LINK
https://github.com/fleschutz/talk2windows
#>
#requires -version 2
param([string]$filePattern = "$PSScriptRoot\scripts\*.ps1", [string]$app = "terminal", [string]$targetFile = "$HOME\.serenade\scripts\talk2windows.js")
function AddVoiceCmd { param([string]$phrase, [string]$scriptName)
$phrase = $phrase -replace "-"," "
"serenade.global().command(W+`"$phrase`",async(api)=>{await api.runShell(A,[N,B+`"$scriptName`"]);});" | Add-Content "$targetFile"
}
function AddMatchingVoiceCmd { param([string]$phrase, [string]$scriptName)
$phrase = $phrase -replace "-"," "
"serenade.global().command(W+`"$phrase`",async(api,matches)=>{await api.runShell(A,[N,B+`"$scriptName`",matches.text]);});" | Add-Content "$targetFile"
}
try {
Clear
""
"Setup of Talk2Windows"
"====================="
""
Write-Host " 1. Searching for Serenade application..." -noNewline
if (!(Test-Path "~\.serenade" -pathType container)) { throw "Serenade app isn't installed yet - please download and install it from https://serenade.ai" }
Write-Host " OK"
$wakeWord = Read-Host " 2. Enter your wake word, e.g. Alexa, Computer, Jarvis, Siri, or Windows"
$scripts = Get-ChildItem "$filePattern"
" 3. Importing $($scripts.Count) scripts from: $filePattern..."
Write-Host " 4. Exporting as Serenade's voice commands to: $targetFile..." -noNewline
"/* DO NOT EDIT! This file has been generated automatically by talk2windows */" | Set-Content "$targetFile"
"var A = `"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`";" | Add-Content "$targetFile"
$scriptRoot = "$PSScriptRoot"
$scriptRoot = $scriptRoot -replace "\\","\\"
"var B = `"$scriptRoot\\scripts\\`";" | Add-Content "$targetFile"
"var N = `"-NoProfile`";" | Add-Content "$targetFile"
"var W = `"$($wakeWord.toLower()) `";" | Add-Content "$targetFile"
foreach($script in $scripts) {
$baseName = $script.basename
if ($baseName[0] -eq "_") { continue } # internal script
if ($baseName -like "*-XYZ*") {
$phrase = $baseName -replace "-XYZ","-<%text%>"
AddMatchingVoiceCmd $phrase "$baseName.ps1"
} elseif ($baseName -like "*-is-*") {
AddVoiceCmd $baseName "$baseName.ps1"
$phrase = $baseName -replace "-is-","'s-"
AddVoiceCmd $phrase "$baseName.ps1"
} elseif ($baseName -like "i-am-*") {
AddVoiceCmd $baseName "$baseName.ps1"
$phrase = $baseName -replace "-am-","'m-"
AddVoiceCmd $phrase "$baseName.ps1"
} elseif ($baseName -like "i-will-*") {
AddVoiceCmd $baseName "$baseName.ps1"
$phrase = $baseName -replace "-will-","'ll-"
AddVoiceCmd $phrase "$baseName.ps1"
} else {
AddVoiceCmd $baseName "$baseName.ps1"
}
}
Write-Host " OK"
""
""
""
""
"How to use Talk2Windows"
"-----------------------"
""
" 1. Put your headset on and check that it's working."
""
" 2. Launch Serenade and click the slider to switch from Paused to Listening mode."
" Raise the mic audio level in case a 'low voice' is shown."
""
" 3. Say a voice command like `"$wakeWord, hi`" with a calm voice into the mic."
" See all supported voice commands at: https://github.com/fleschutz/talk2windows"
""
exit 0 # success
} catch {
Write-Error "ERROR: $($Error[0])"
exit 1
}