public STTParams GetSTTToken() { string token = null; var tokenKeeper = TokenState.TokenSTT; if (tokenKeeper.IsValid()) { token = tokenKeeper.TokenValue; } else { HttpClient client = NetworkHelper.ConstruirHttpClient(this.configSettings.ProxyUse, this.configSettings.ProxyHost, this.configSettings.ProxyPort, this.configSettings.ProxyUser, this.configSettings.ProxyPassword); string speechToTextUser = this.configSettings.SpeechToTextUsername; string speechToTextPassword = this.configSettings.SpeechToTextPassword; var byteArray = Encoding.ASCII.GetBytes($"{speechToTextUser}:{speechToTextPassword}"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); HttpResponseMessage response = client.GetAsync(this.configSettings.TextToSpeechWatsonUrlAuthAPI).Result; HttpContent content = response.Content; token = content.ReadAsStringAsync().Result; tokenKeeper.TokenValue = token; tokenKeeper.CreationDate = DateTime.Now; } STTParams sttParams = new STTParams() { Token = token, Model = this.configSettings.TextToSpeechModel, OutputElement = this.configSettings.TextToSpeechOutputElement }; return(sttParams); }
public TTSParams GetTTSToken() { string token = null; var tokenKeeper = TokenState.TokenTTS; if (tokenKeeper.IsValid()) { token = tokenKeeper.TokenValue; } else { HttpClient client = NetworkHelper.ConstruirHttpClient(this.configSettings.ProxyUse, this.configSettings.ProxyHost, this.configSettings.ProxyPort, this.configSettings.ProxyHost, this.configSettings.ProxyPassword); string textToSpeechUser = this.configSettings.TextToSpeechUsername; string textToSpeechPassword = this.configSettings.TextToSpeechPassword; var byteArray = Encoding.ASCII.GetBytes($"{textToSpeechUser}:{textToSpeechPassword}"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); HttpResponseMessage response = client.GetAsync(this.configSettings.SpeechToTextWatsonUrlAuthAPI).Result; HttpContent content = response.Content; token = content.ReadAsStringAsync().Result; tokenKeeper.TokenValue = token; tokenKeeper.CreationDate = DateTime.Now; } TTSParams tsParams = new TTSParams() { Text = "", Token = token, Voice = this.configSettings.SpeechToTextVoice }; return(tsParams); }