-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSpeak-AsCharacter.ps1
94 lines (90 loc) · 2.64 KB
/
Speak-AsCharacter.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
94
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateSet(
"craig-ferguson"
,"gilbert-gottfried"
,"sam-altman"
,"david-attenborough"
,"alan-rickman"
,"bart-simpson"
,"betty-white"
,"bill-gates"
,"bill-nye"
,"bryan-cranston"
,"christopher-lee"
,"danny-devito"
,"dr-phil-mcgraw"
,"j-k-simmons"
,"judi-dench"
,"leonard-nimoy"
,"neil-degrasse-tyson"
,"palmer-luckey"
,"peter-thiel"
,"richard-nixon"
,"jimmy-carter"
,"ronald-reagan"
,"bill-clinton"
,"george-w-bush"
,"shohreh-aghdashloo"
,"wilford-brimley"
,"anderson-cooper"
,"ben-stein"
,"david-cross"
,"hillary-clinton"
,"james-earl-jones"
,"john-oliver"
,"larry-king"
,"mark-zuckerberg"
,"fred-rogers"
,"sarah-palin"
,"tupac-shakur"
,"arnold-schwarzenegger"
,"george-takei"
,"paul-graham"
,"barack-obama"
)]
[string]$SpeakerName,
[Parameter(Position = 1, Mandatory = $true)]
[string]$Text,
[string]$Outfile
)
begin {
$SoundPlayer = [System.Media.SoundPlayer]::new()
$Headers = @{
"Accept"="application/json"
"User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Edg/84.0.522.52"
"Origin"="https://vo.codes"
"Sec-Fetch-Site"="cross-site"
"Sec-Fetch-Mode"="cors"
"Sec-Fetch-Dest"="empty"
"Referer"="https://vo.codes/"
"Accept-Encoding"="gzip, deflate, br"
"Accept-Language"="en-US,en;q=0.9"
}
}
process {
Write-Host "Submitting Request, this may take a while"
$Body = @{
text = $Text
speaker = $SpeakerName
} | Convertto-Json
$Response = Invoke-WebRequest -Uri "https://mumble.stream/speak_spectrogram" `
-Method "POST" -Headers $Headers -ContentType "application/json" -Body $Body
if($Response.StatusCode -ne [System.Net.HttpStatusCode]::OK){
Write-Error "Unacceptable Response"
return $Response
}
$AudioData = $Response | ConvertFrom-Json
$AudioData
}
end {
Write-Host "Playing Audio"
if(-not ([string]::IsNullOrEmpty($OutFile))){
[System.IO.File]::WriteAllBytes($OutFile,[Convert]::FromBase64String($AudioData.audio_base64))
}else{
$MemStream = [System.IO.MemoryStream]::new([Convert]::FromBase64String($AudioData.audio_base64))
$SoundPlayer.Stream = $MemStream
$SoundPlayer.Play()
}
}