@echo off
chcp 850 > nul
color 0A
cls
SETLOCAL ENABLEEXTENSIONS
echo.

set lang=eng
reg query "HKCU\Control Panel\International" /v "locale" | find "0406" >nul 2>&1
if  %ERRORLEVEL%==0 set lang=dan && goto dansk

echo     Update Windows' Registry for use of installed voices with MS Speech API
echo.
echo.
echo Note - this script must be run as administrator.
echo.
choice /C YN /N /M "Do you wish to proceed [Y/N]?"
if not %ERRORLEVEL%==1 goto slut

ver | find "10." >nul 2>&1
if %ERRORLEVEL%==1 goto nexte

echo.
echo Checking Windows' Registry for MS OneCore voices...
echo.
reg query "HKLM\SOFTWARE\Microsoft\Speech_OneCore\Voices" >nul 2>&1
if %ERRORLEVEL%==1 (echo There are no MS OneCore voices to add to HKLM\SOFTWARE\Microsoft\Speech) && goto nexte

choice /C YN /N /M "MS OneCore voices found. Register for use with MS Speech API [Y/N]?"
if not %ERRORLEVEL%==1 goto nexte

echo.
reg copy "HKLM\SOFTWARE\Microsoft\Speech_OneCore\Voices" "HKLM\SOFTWARE\Microsoft\Speech\Voices" /s /f >nul 2>&1
reg copy "HKLM\SOFTWARE\Wow6432Node\Microsoft\Speech_OneCore\Voices" "HKLM\SOFTWARE\Wow6432Node\Microsoft\Speech\Voices" /s /f >nul 2>&1
for /f "tokens=3*" %%A in ('reg query "HKCU\SOFTWARE\Microsoft\Speech_OneCore\Settings\TextToSpeech" /v Voice 2^>nul') do reg add "HKCU\SOFTWARE\Microsoft\Speech_OneCore\Voices" /v DefaultTokenId /t REG_SZ /d "%%A" /f >nul 2>&1
if %ERRORLEVEL%==1 (echo Can not add keys to the Registry - maybe the script isn't run as administrator!) && goto nexte
echo MS OneCore voices added to HKLM\SOFTWARE\Microsoft\Speech\Voices

:nexte
echo.
echo.
echo.
echo Checking Windows' Registry for MS Server Speech voices...
echo.
reg query "HKLM\SOFTWARE\Microsoft\Speech Server\v11.0\Voices" >nul 2>&1
if %ERRORLEVEL%==1 (echo There are no MS Server Speech voices to add to HKLM\SOFTWARE\Microsoft\Speech) && goto ende

choice /C YN /N /M "MS Server Speech voices found. Register for use with MS Speech API [Y/N]?"
if not %ERRORLEVEL%==1 goto ende

echo.
reg copy "HKLM\SOFTWARE\Microsoft\Speech Server\v11.0\Voices" "HKLM\SOFTWARE\Microsoft\Speech\Voices" /s /f >nul 2>&1
reg copy "HKLM\SOFTWARE\Wow6432Node\Microsoft\Speech Server\v11.0\Voices" "HKLM\SOFTWARE\Wow6432Node\Microsoft\Speech\Voices" /s /f >nul 2>&1
if %ERRORLEVEL%==1 (echo Can not add keys to the Registry - maybe the script isn't run as administrator!) && goto ende
echo MS Server Speech voices added to HKLM\SOFTWARE\Microsoft\Speech\Voices

:ende
echo.
echo.
echo Press any key to finish . . .
pause > nul
goto slut



:dansk
echo   Opdater Windows' Registry for brug af installerede stemmer med MS Speech API
echo.
echo.
echo Obs - dette script skal k›res som administrator.
echo.
choice /C JN /N /M "�nsker du at forts‘tte [J/N]?"
if not %ERRORLEVEL%==1 goto slut

ver | find "10." >nul 2>&1
if %ERRORLEVEL%==1 goto nextd

echo.
echo Checker Windows' Registry for MS OneCore stemmer...
echo.
reg query "HKLM\SOFTWARE\Microsoft\Speech_OneCore\Voices" >nul 2>&1
if %ERRORLEVEL%==1 (echo Der er ingen MS OneCore stemmer at f›je til HKLM\SOFTWARE\Microsoft\Speech) && goto nextd

choice /C JN /N /M "MS OneCore stemmer fundet. Registrer for brug med MS Speech API [J/N]?"
if not %ERRORLEVEL%==1 goto nextd

echo.
reg copy "HKLM\SOFTWARE\Microsoft\Speech_OneCore\Voices" "HKLM\SOFTWARE\Microsoft\Speech\Voices" /s /f >nul 2>&1
reg copy "HKLM\SOFTWARE\Wow6432Node\Microsoft\Speech_OneCore\Voices" "HKLM\SOFTWARE\Wow6432Node\Microsoft\Speech\Voices" /s /f >nul 2>&1
for /f "tokens=3*" %%A in ('reg query "HKCU\SOFTWARE\Microsoft\Speech_OneCore\Settings\TextToSpeech" /v Voice 2^>nul') do reg add "HKCU\SOFTWARE\Microsoft\Speech_OneCore\Voices" /v DefaultTokenId /t REG_SZ /d "%%A" /f >nul 2>&1
if %ERRORLEVEL%==1 (echo Kan ikke f›je n›gler til Registry - m†ske k›res scripet ikke som administrator!) && goto nextd
echo MS OneCore stemmer f›jet til HKLM\SOFTWARE\Microsoft\Speech\Voices

:nextd
echo.
echo.
echo.
echo Checker Windows' Registry for MS Server Speech stemmer...
echo.
reg query "HKLM\SOFTWARE\Microsoft\Speech Server\v11.0\Voices" >nul 2>&1
if %ERRORLEVEL%==1 (echo Der er ingen MS Server Speech stemmer at f›je til HKLM\SOFTWARE\Microsoft\Speech) && goto endd

choice /C JN /N /M "MS Server Speech stemmer fundet. Registrer for brug med MS Speech API [J/N]?"
if not %ERRORLEVEL%==1 goto endd

echo.
reg copy "HKLM\SOFTWARE\Microsoft\Speech Server\v11.0\Voices" "HKLM\SOFTWARE\Microsoft\Speech\Voices" /s /f >nul 2>&1
reg copy "HKLM\SOFTWARE\Wow6432Node\Microsoft\Speech Server\v11.0\Voices" "HKLM\SOFTWARE\Wow6432Node\Microsoft\Speech\Voices" /s /f >nul 2>&1
if %ERRORLEVEL%==1 (echo Kan ikke f›je n›gler til Registry - m†ske k›res scripet ikke som administrator!) && goto endd
echo MS Server Speech stemmer f›jet til HKLM\SOFTWARE\Microsoft\Speech\Voices

:endd
echo.
echo.
echo Tryk p† en vilk†rlig tast for at afslutte . . .
pause > nul

:slut
ENDLOCAL