Clean up set-voice script

This commit is contained in:
Michael Taboada 2022-08-23 09:56:20 -07:00
parent f523b51327
commit 4db6eae6a0

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Set Voice # Set Voice
# Set the default wine voice based on installed options. # Set the default wine voice ba$sed on installed options.
# Rate can be specified as a numeric argument to this script, 1 through 9. # Rate can be specified as a numeric argument to this script, 1 through 9.
# The default rate is 7 # The default rate is 7
@ -8,7 +8,7 @@
# ■The contents of this file are subject to the Common Public Attribution # ■The contents of this file are subject to the Common Public Attribution
# License Version 1.0 (the ■License■); you may not use this file except in # License Version 1.0 (the ■License■); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at # compliance with the License. You may obtain a copy of the License at
# https://opensource.org/licenses/CPAL-1.0. The License is based on the Mozilla Public License Version # https://opensource.org/licenses/CPAL-1.0. The License is ba$sed on the Mozilla Public License Version
# 1.1 but Sections 14 and 15 have been added to cover use of software over a # 1.1 but Sections 14 and 15 have been added to cover use of software over a
# computer network and provide for limited attribution for the Original # computer network and provide for limited attribution for the Original
# Developer. In addition, Exhibit A has been modified to be consistent with # Developer. In addition, Exhibit A has been modified to be consistent with
@ -44,6 +44,13 @@
#--code-- #--code--
# Set a variable to make mac compatibility easier...
sed="sed"
grep="grep"
if [[ "$(uname)" == "Darwin" ]]; then
sed="gsed"
grep="ggrep"
fi
# Settings to improve accessibility of dialog. # Settings to improve accessibility of dialog.
export DIALOGOPTS='--insecure --no-lines --visit-items' export DIALOGOPTS='--insecure --no-lines --visit-items'
# Turn off debug messages # Turn off debug messages
@ -116,11 +123,7 @@ menulist() {
restore_voice() { restore_voice() {
if [[ $doRestore -eq 0 ]]; then if [[ $doRestore -eq 0 ]]; then
wineserver -k # If we don't do this it's likely wine will overwrite our reverted change or even clobber the registry key entirely wineserver -k # If we don't do this it's likely wine will overwrite our reverted change or even clobber the registry key entirely
if [[ "$(uname)" == "Darwin" ]]; then $sed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"/"DefaultTokenId"="'"${oldVoice//\\/\\\\}"'"/g' "${WINEPREFIX}/user.reg"
gsed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"/"DefaultTokenId"="'"${oldVoice//\\/\\\\}"'"/g' "${WINEPREFIX}/user.reg"
else
sed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"/"DefaultTokenId"="'"${oldVoice//\\/\\\\}"'"/g' "${WINEPREFIX}/user.reg"
fi
fi fi
} }
@ -134,16 +137,10 @@ set_voice() {
counter=$(( $counter + 1 )) counter=$(( $counter + 1 ))
done done
fullVoice="${voiceListFullName[$counter]}" fullVoice="${voiceListFullName[$counter]}"
fullVoice="${fullVoice/RHVoice/RHVoice\\\\bdl}"
wineserver -k # If we don't do this it's likely wine will overwrite our reverted change or even clobber the registry key entirely wineserver -k # If we don't do this it's likely wine will overwrite our reverted change or even clobber the registry key entirely
# Remove any existing rate change for voices # Remove any existing rate change for voices
if [[ "$(uname)" == "Darwin" ]]; then $sed -i '/"DefaultTTSRate"=dword:/d' "${WINEPREFIX}/user.reg"
gsed -i '/"DefaultTTSRate"=dword:/d' "${WINEPREFIX}/user.reg" $sed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\'"${fullVoice//\\/\\\\}"'"\n"DefaultTTSRate"=dword:0000000'${2:-7}'/g' "${WINEPREFIX}/user.reg"
gsed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\'"${fullVoice//\\/\\\\}"'"\n"DefaultTTSRate"=dword:0000000'${2:-7}'/g' "${WINEPREFIX}/user.reg"
else
sed -i '/"DefaultTTSRate"=dword:/d' "${WINEPREFIX}/user.reg"
sed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\'"${fullVoice//\\/\\\\}"'"\n"DefaultTTSRate"=dword:0000000'${2:-7}'/g' "${WINEPREFIX}/user.reg"
fi
} }
test_voice() { test_voice() {
@ -156,13 +153,8 @@ test_voice() {
counter=$(( $counter + 1 )) counter=$(( $counter + 1 ))
done done
fullVoice="${voiceListFullName[$counter]}" fullVoice="${voiceListFullName[$counter]}"
fullVoice="${fullVoice/RHVoice/RHVoice\\\\bdl}"
wineserver -k # If we don't do this it's likely wine will overwrite our reverted change or even clobber the registry key entirely wineserver -k # If we don't do this it's likely wine will overwrite our reverted change or even clobber the registry key entirely
if [[ "$(uname)" == "Darwin" ]]; then $sed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\'"${fullVoice//\\/\\\\}"'"/g' "${WINEPREFIX}/user.reg"
gsed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\'"${fullVoice//\\/\\\\}"'"/g' "${WINEPREFIX}/user.reg"
else
sed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\'"${fullVoice//\\/\\\\}"'"/g' "${WINEPREFIX}/user.reg"
fi
cat << "EOF" > /tmp/speak.vbs cat << "EOF" > /tmp/speak.vbs
dim speechobject dim speechobject
set speechobject=createobject("sapi.spvoice") set speechobject=createobject("sapi.spvoice")
@ -186,21 +178,13 @@ wine cscript "z:\tmp\speak.vbs"
# Create an array of available voices. # Create an array of available voices.
ifs="$IFS" ifs="$IFS"
IFS=$'\n' IFS=$'\n'
if [[ "$(uname)" == "Darwin" ]]; then voiceListFullName=($($grep -P '\[Software\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^\\]+\].*' "${WINEPREFIX}/system.reg" | $sed -E -e 's/\[([^]]+)\].*/\1/g'))
voiceListFullName=($(ggrep -P '\[Software\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^\\]+\].*' "${WINEPREFIX}/system.reg" | sed -E -e 's/\[([^]]+)\].*/\1/g'))
else
voiceListFullName=($(grep -P '\[Software\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^\\]+\].*' "${WINEPREFIX}/system.reg" | sed -E -e 's/\[([^]]+)\].*/\1/g'))
fi
IFS="$ifs" IFS="$ifs"
voiceList=() voiceList=()
for x in "${voiceListFullName[@]}" ; do for x in "${voiceListFullName[@]}" ; do
voiceList+=("$(echo "$x" | rev | cut -d\\ -f1 | rev)") voiceList+=("$(echo "$x" | $sed -E -e 's/Software\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\(.+)/\1/g')")
done done
if [[ "$(uname)" == "Darwin" ]]; then oldVoice="$($grep -P '"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"' "${WINEPREFIX}/user.reg" | $sed -E -e 's/"DefaultTokenId"="([^"]+)"/\1/g')"
oldVoice="$(ggrep -P '"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"' "${WINEPREFIX}/user.reg" | sed -E -e 's/"DefaultTokenId"="([^"]+)"/\1/g')"
else
oldVoice="$(grep -P '"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Token(Enum|)s\\\\[^"]+"' "${WINEPREFIX}/user.reg" | sed -E -e 's/"DefaultTokenId"="([^"]+)"/\1/g')"
fi
exit=1 exit=1
while [[ $exit -ne 0 ]] ; do while [[ $exit -ne 0 ]] ; do
voice="$(menulist "${voiceList[@]}")" voice="$(menulist "${voiceList[@]}")"