summaryrefslogtreecommitdiff
path: root/crystal
diff options
context:
space:
mode:
Diffstat (limited to 'crystal')
-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" )