@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 default voice with Web Speech API
echo.
echo.
echo Note - this script must be run under Window 10 or newer.
echo.
choice /C YN /N /M "Do you wish to proceed [Y/N]?"
if not %ERRORLEVEL%==1 goto slut
echo.

ver | find "10." >nul 2>&1
if %ERRORLEVEL%==1 (echo This script is only for Windows 10 and newer!) && goto ende

echo Checking Windows' Registry for MS OneCore default voice...
echo.
reg query "HKCU\SOFTWARE\Microsoft\Speech_OneCore\Settings\TextToSpeech" >nul 2>&1
if %ERRORLEVEL%==1 (echo There is no default voice set for Windows' Speech) && goto ende

choice /C YN /N /M "Default voice found. Register for use with MS Speech API [Y/N]?"
if not %ERRORLEVEL%==1 goto ende

echo.
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 Could not add keys to the Registry!) && goto ende
echo Default voice added to HKCU\SOFTWARE\Microsoft\Speech_OneCore\Voices

:ende
echo.
echo.
echo Press any key to finish . . .
pause > nul
goto slut



:dansk
echo   Opdater Windows' Registry for brug af standard stemme med Web Speech API
echo.
echo.
echo Obs - dette script skal k›res under Windows 10 eller nyere.
echo.
choice /C JN /N /M "�nsker du at forts‘tte [J/N]?"
if not %ERRORLEVEL%==1 goto slut
echo.

ver | find "10." >nul 2>&1
if %ERRORLEVEL%==1 (echo Dette script er kun for Windows 10 og nyere!) && goto endd

echo Checker Windows' Registry for MS OneCore standard stemme...
echo.
reg query "HKLM\SOFTWARE\Microsoft\Speech_OneCore\Voices" >nul 2>&1
if %ERRORLEVEL%==1 (echo Der er ingen standard stemme sat for Windows' Tale) && goto endd

choice /C JN /N /M "Standard stemme fundet. Registrer for brug med Web Speech API [J/N]?"
if not %ERRORLEVEL%==1 goto endd

echo.
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 Kunne ikke f›je n›gler til Registry!) && goto endd
echo Standard stemme f›jet til HKCU\SOFTWARE\Microsoft\Speech_OneCore\Voices

:endd
echo.
echo.
echo Tryk p† en vilk†rlig tast for at afslutte . . .
pause > nul

:slut
ENDLOCAL