Authorize

Neural TTSaaS is a hosted service on the Nuance Mix platform. To access this service, your client applications must be authorized with an access token generated by the OAuth 2 protocol.

In order to request a token, you need your Mix client ID and secret as described in Prerequisites from Mix. Once you have these credentials, you can request an access token in several ways.

The sample client supports two methods.

Let client generate token

The client includes token-generation code, checking first to see whether the token has expired. To use this method, pass your credentials and the location of the OAuth server in the --clientID, --clientSecret, and --oauthURL arguments.

Edit your run script, run-client.sh or run-client.bat, to add your Mix client ID and secret.

#!/bin/bash

CLIENT_ID=<Mix client ID, starting with appID:>
SECRET=<Mix client secret>
# Change colons (:) to %3A in client ID 
CLIENT_ID=${CLIENT_ID//:/%3A}

python3 client.py --oauthURL https://auth.crt.nuance.com/oauth2/token \
--clientID $CLIENT_ID --clientSecret $SECRET \
--secure --serverUrl tts.api.nuance.com --neural --saveAudio --saveAudioAsWav
@echo off
setlocal enabledelayedexpansion

set CLIENT_ID=<Mix client ID, starting with appID:>
set SECRET=<Mix client secret>
rem Change colons (:) to %3A in client ID 
set CLIENT_ID=!CLIENT_ID::=%%3A!

python client.py --oauthURL https://auth.crt.nuance.com/oauth2/token ^
--clientID %CLIENT_ID% --clientSecret %SECRET% ^
--secure --serverUrl tts.api.nuance.com --neural --saveAudio --saveAudioAsWav

Generate token manually

Alternatively, you may generate the token manually and pass it to the client as an environment variable in the --token argument.

This token expires after a short time (around 15 minutes) so must be regenerated frequently, but the number of requests is limited for security reasons.

To use this method, create a Linux shell script (.sh) or a Windows batch file (.bat) and copy in the following lines, adding your Mix client ID and secret.

On Linux, give the shell script execute permission with chmod +x run-token-client.sh.

#!/bin/bash

CLIENT_ID=<Mix client ID, starting with appID:>
SECRET=<Mix client secret>
# Change colons (:) to %3A in client ID 
CLIENT_ID=${CLIENT_ID//:/%3A}

export MY_TOKEN="`curl -s -u "$CLIENT_ID:$SECRET" \
"https://auth.crt.nuance.com/oauth2/token" \
-d 'grant_type=client_credentials' -d 'scope=asr nlu tts' \
| python -c 'import sys, json; print(json.load(sys.stdin)["access_token"])'`"

python3 client.py --token $MY_TOKEN --secure \
--serverUrl tts.api.nuance.com --neural --saveAudio --saveAudioAsWav
@echo off
setlocal enabledelayedexpansion

set CLIENT_ID=<Mix client ID, starting with appID:>
set SECRET=<Mix client secret>
rem Change colons (:) to %3A in client ID 
set CLIENT_ID=!CLIENT_ID::=%%3A!

set command=curl -s -u %CLIENT_ID%:%SECRET% ^
-d "grant_type=client_credentials" -d "scope=tts" ^
"https://auth.crt.nuance.com/oauth2/token"

for /f "delims={}" %%a in ('%command%') do (
    for /f "tokens=1 delims=:, " %%b in ("%%a") do set key=%%b
    for /f "tokens=2 delims=:, " %%b in ("%%a") do set value=%%b
    goto done:
)

:done
rem Check if the token was found
if not !key!=="access_token" (
    echo Access token not found^^!
    pause
    exit
)

rem Remove quotes
set MY_TOKEN=!value:"=!

python client.py --token %MY_TOKEN% --secure ^
--serverUrl tts.api.nuance.com --neural --saveAudio --saveAudioAsWav