wineserver -k # If we don't do this it's likely wine will overwrite our reverted change or even clobber the registry key entirely
sed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Tokens\\\\[^"]+"/"DefaultTokenId"="'"${oldVoice//\\/\\\\}"'"/g'"${WINEPREFIX}/user.reg"
sed -i '/"DefaultTTSRate"=dword:/d'"${WINEPREFIX}/user.reg"
sed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Tokens\\\\[^"]+"/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\'"${fullVoice//\\/\\\\}"'"\n"DefaultTTSRate"=dword:0000000'${2:-7}'/g'"${WINEPREFIX}/user.reg"
wineserver -k # If we don't do this it's likely wine will overwrite our reverted change or even clobber the registry key entirely
sed -i -E -e 's/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\(SOFTWARE|Software)\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Tokens\\\\[^"]+"/"DefaultTokenId"="HKEY_LOCAL_MACHINE\\\\'"${fullVoice//\\/\\\\}"'"/g'"${WINEPREFIX}/user.reg"
cat << "EOF" > /tmp/speak.vbs
dim speechobject
setspeechobject=createobject("sapi.spvoice")
speechobject.speak "This is a test of your chosen voice. It contains multiple sentences and punctuation, and is designed to give a full representation of this voices qualities."
EOF
wine cscript "z:\tmp\speak.vbs"
}
# Handle voice restore, but only if voice changed
doRestore=1
trap restore_voice SIGINT
# Create an array of available voices.
ifs="$IFS"
IFS=$'\n'
voiceListFullName=($(grep -P '\[Software\\\\(Wow6432Node\\\\|)Microsoft\\\\Speech\\\\Voices\\\\Tokens\\\\[^\\]+\].*'"${WINEPREFIX}/system.reg"| sed -E -e 's/\[([^]]+)\].*/\1/g'))