summaryrefslogtreecommitdiff
path: root/crystal/bungmobott.cr
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk+git@omgwallhack.org>2022-07-07 22:47:32 -0700
committerJoe Rayhawk <jrayhawk+git@omgwallhack.org>2022-07-07 22:47:32 -0700
commit177a8167a268e8260fcb5488ef26f972db12d95c (patch)
tree368dbb4b7fc01370c570679714a4596926aebf53 /crystal/bungmobott.cr
parentf51cf03b65c84b67b1a5d6927899c30e7c563e1b (diff)
downloadtwitchtools-177a8167a268e8260fcb5488ef26f972db12d95c.tar.gz
twitchtools-177a8167a268e8260fcb5488ef26f972db12d95c.zip
crystal/bungmobott.cr: add regeneratevoicelist command
Diffstat (limited to 'crystal/bungmobott.cr')
-rwxr-xr-xcrystal/bungmobott.cr68
1 files changed, 54 insertions, 14 deletions
diff --git a/crystal/bungmobott.cr b/crystal/bungmobott.cr
index 3b592e9..241db6d 100755
--- a/crystal/bungmobott.cr
+++ b/crystal/bungmobott.cr
@@ -56,8 +56,8 @@ else
end
# enable aws?
-if ! File.exists?( ENV["USERPROFILE"] + "\\.aws\\credentials" )
- STDERR.puts "Warning: #{ENV["USERPROFILE"]}\\.aws\\credentials is missing; AWS voices disabled."
+if ! File.exists?( Path.home./("\\.aws\\credentials") )
+ STDERR.puts "Warning: #{Path.home}\\.aws\\credentials is missing; AWS voices disabled."
aws = false
elsif ! Process.find_executable( "aws.exe" )
STDERR.puts "Warning: aws.exe is missing; AWS voices disabled."
@@ -116,7 +116,7 @@ def urbandef( term : String )
return json["list"][0]["definition"].to_s.gsub( /[\[\]]/, "" ).gsub( /\n/, "" )
end
-# Currently only used in flags?(:unix)
+# Currently only used in flag?(:unix)
def t2smsg( settings : Hash(String, String), msg : String)
if File.exists?( settings["statedir"] + "/.t2s.sock" )
sock = Socket.unix
@@ -233,7 +233,7 @@ def t2s( t2sipc : Channel, settings : Hash(String, String), userdir : String, ch
end
{% if flag?(:windows) %} # send to thread
t2sipc.send( { voice, "#{namesub} #{text}" } )
- {% elsif flag?(:unix) %} # send to socket
+ {% else %} # send to socket
t2smsg( settings, "#{voice} #{namesub} #{text}" )
{% end %}
return( voice )
@@ -265,7 +265,7 @@ def reversesource( scenes : Hash( String, Hash( String, Hash( String, Int64 | Fl
return sourcemap
end
-def playmp3file( filepath : String )
+def playaudiofile( filepath : String )
p = Process.new(
"powershell.exe",
[ "-Command", "#Set-PSDebug -Trace 1;
@@ -287,7 +287,7 @@ end
macro testrefuser2uid( path )
{% if flag?(:windows) %}
File.exists?( {{path}} ) && ( File.read( {{ path }} ) =~ /^[0-9]+$/ )
- {% elsif flag?(:unix) %}
+ {% else %}
File.symlink?( {{path}} )
{% end %}
end
@@ -295,8 +295,7 @@ end
macro genrefuser2uid( path, uid, depth )
{% if flag?(:windows) %}
File.write( {{path}}, {{uid}}.to_s )
- {% elsif flag?(:unix) %}
- pp "unix"
+ {% else %}
File.symlink( "../"*{{depth}} + "uids/#{{{uid}}}", {{path}} )
{% end %}
end
@@ -362,21 +361,20 @@ spawn do
"languageCode" => match[1],
},
}
- body = request.to_json
ssl_context = OpenSSL::SSL::Context::Client.new
ssl_context.verify_mode = OpenSSL::SSL::VerifyMode::NONE
headers = HTTP::Headers.new
headers["Content-Type"] = "application/json; charset=utf-8"
- response = HTTP::Client.exec( "POST", "https://texttospeech.googleapis.com/v1/text:synthesize?key=#{settings["gcloud_token"]}", headers, body, tls: ssl_context )
+ response = HTTP::Client.exec( "POST", "https://texttospeech.googleapis.com/v1/text:synthesize?key=#{settings["gcloud_token"]}", headers, request.to_json, tls: ssl_context )
response.body
- filepath="#{settings["tempdir"]}#{Time.utc.to_unix}.mp3"
+ filepath="#{settings["tempdir"]}#{Time.utc.to_unix_ms}.mp3"
json=JSON.parse(response.body)
File.write( filepath, Base64.decode_string( json["audioContent"].as_s ) )
- playmp3file( filepath )
+ playaudiofile( filepath )
File.delete( filepath )
elsif aws # AWS polly voices
filepath="#{settings["tempdir"]}#{Time.utc.to_unix}.mp3"
@@ -390,7 +388,7 @@ spawn do
], output: STDOUT, error: STDERR
)
p.wait
- playmp3file( filepath )
+ playaudiofile( filepath )
File.delete( filepath )
else # unknown
STDERR.puts "Voice not recognized or available."
@@ -616,6 +614,49 @@ loop do
else
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") )
+ ircipc.send( { "##{settings["channel"]}", "| Regenerated voicelist." } )
elsif ( ( cmd =~ /^(voices|voicelist)$/ ) && ( mod || sub ) )
bot.message( "##{settings["channel"]}", "| https://bungmonkey.omgwallhack.org/voicelist.txt" )
elsif ( ( cmd =~ /^(setvoice|voice)$/ ) && ( mod || sub ) )
@@ -815,7 +856,6 @@ loop do
if match[2]? && match[2] =~ /^[a-z]+$/
ircipc.send( { "##{settings["channel"]}", "| overlay requires an argument consisting wholly of lower case characters."} )
effectsmsg( settings, "overlay #{match[2]}" )
- else
end
{% if flag?(:unix) %}
elsif ( cmd =~ /^(system|dxdiag|computer)$/ )