summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk+git@omgwallhack.org>2022-07-07 23:33:41 -0700
committerJoe Rayhawk <jrayhawk+git@omgwallhack.org>2022-07-07 23:33:41 -0700
commit1d16db959a75a749f57d423436dc132373cdf43b (patch)
tree60212e666c4242043c74dc3cc623dd5378073213
parent177a8167a268e8260fcb5488ef26f972db12d95c (diff)
downloadtwitchtools-1d16db959a75a749f57d423436dc132373cdf43b.tar.gz
twitchtools-1d16db959a75a749f57d423436dc132373cdf43b.zip
bungmobott: generate voicelist.txt if missing
-rwxr-xr-xcrystal/bungmobott.cr95
1 files changed, 52 insertions, 43 deletions
diff --git a/crystal/bungmobott.cr b/crystal/bungmobott.cr
index 241db6d..5e0caed 100755
--- a/crystal/bungmobott.cr
+++ b/crystal/bungmobott.cr
@@ -284,6 +284,51 @@ def playaudiofile( filepath : String )
p.wait
end
+def regeneratevoicelist( settings : Hash( String, String ), aws : Bool, gcloud : Bool )
+ voices = Hash(String, String).new
+ if aws
+ JSON.parse( `aws polly describe-voices` )["Voices"].as_a.each do | v |
+ voices[ v["Id"].as_s.downcase ] = v["Id"].as_s
+ end
+ end
+ if gcloud
+ ssl_context = OpenSSL::SSL::Context::Client.new
+ {% if flag?(:windows) %}
+ ssl_context.verify_mode = OpenSSL::SSL::VerifyMode::NONE
+ {% end %}
+ headers = HTTP::Headers.new
+ headers["Content-Type"] = "application/json; charset=utf-8"
+
+ response = HTTP::Client.exec( "GET", "https://texttospeech.googleapis.com/v1/voices?key=#{settings["gcloud_token"]}", headers, nil, tls: ssl_context )
+
+ JSON.parse( response.body )["voices"].as_a.each do | v |
+ voices[ v["name"].as_s.downcase ] = v["name"].as_s
+ end
+ end
+ {% if flag?(:windows) %}
+ p = Process.new(
+ "powershell.exe",
+ [ "-Command", "
+ Add-Type -AssemblyName System.Speech;
+ $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer;
+ $speak.GetInstalledVoices().VoiceInfo | Select-Object Name
+ "],
+ output: Process::Redirect::Pipe
+ )
+ p.output.each_line do | v |
+ v = v.gsub(/ +$/, "")
+ v = v.gsub(/ Desktop$/, "")
+ v = v.gsub( " ", "-" )
+ if v =~ /[A-Za-z0-9]-[A-Za-z0-9]/
+ voices[ v.downcase ] = v
+ end
+ end
+ {% end %}
+
+ File.write( settings["configdir"] + "/voicelist.txt", voices.values.sort.join("\r\n") )
+ return voices
+end
+
macro testrefuser2uid( path )
{% if flag?(:windows) %}
File.exists?( {{path}} ) && ( File.read( {{ path }} ) =~ /^[0-9]+$/ )
@@ -320,8 +365,12 @@ macro temporaryduplicate( item )
end
voices = Hash(String, String).new
-File.each_line( settings["configdir"] + "/voicelist.txt" ) do |line|
- voices[ line.downcase ] = line
+if File.exists?( settings["configdir"] + "/voicelist.txt" )
+ File.each_line( settings["configdir"] + "/voicelist.txt" ) do |line|
+ voices[ line.downcase ] = line
+ end
+else
+ voices = regeneratevoicelist( settings, aws, gcloud )
end
lastvoice = Array(String).new
@@ -615,47 +664,7 @@ loop do
bot.message( "##{settings["channel"]}", "| No voices used so far." )
end
elsif ( ( cmd == "regeneratevoicelist" ) && ( own ) )
- voicelist = Array( String ).new
- if aws
- JSON.parse( `aws polly describe-voices` )["Voices"].as_a.each do | v |
- voicelist.push( v["Name"].as_s )
- end
- end
- if gcloud
- ssl_context = OpenSSL::SSL::Context::Client.new
- {% if flag?(:windows) %}
- ssl_context.verify_mode = OpenSSL::SSL::VerifyMode::NONE
- {% end %}
- headers = HTTP::Headers.new
- headers["Content-Type"] = "application/json; charset=utf-8"
-
- response = HTTP::Client.exec( "GET", "https://texttospeech.googleapis.com/v1/voices?key=#{settings["gcloud_token"]}", headers, nil, tls: ssl_context )
-
- JSON.parse( response.body )["voices"].as_a.each do | v |
- voicelist.push( v["name"].as_s )
- end
- end
- {% if flag?(:windows) %}
- p = Process.new(
- "powershell.exe",
- [ "-Command", "
- Add-Type -AssemblyName System.Speech;
- $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer;
- $speak.GetInstalledVoices().VoiceInfo | Select-Object Name
- "],
- output: Process::Redirect::Pipe
- )
- p.output.each_line do | v |
- v = v.gsub(/ +$/, "")
- v = v.gsub(/ Desktop$/, "")
- v = v.gsub( " ", "-" )
- if v =~ /[A-Za-z0-9]-[A-Za-z0-9]/
- voicelist.push( v )
- end
- end
- {% end %}
-
- File.write( settings["configdir"] + "/voicelist.txt", voicelist.join("\r\n") )
+ voices = regeneratevoicelist( settings, aws, gcloud )
ircipc.send( { "##{settings["channel"]}", "| Regenerated voicelist." } )
elsif ( ( cmd =~ /^(voices|voicelist)$/ ) && ( mod || sub ) )
bot.message( "##{settings["channel"]}", "| https://bungmonkey.omgwallhack.org/voicelist.txt" )