public MemoryStream Synthesize(Text text, string accept = null, string voice = null) { if (text == null) { throw new ArgumentNullException(nameof(text)); } MemoryStream result = null; try { client = client.WithAuthentication(tokenManager.GetToken()); var restRequest = client.PostAsync($"{endpoint}/v1/synthesize"); if (!string.IsNullOrEmpty(accept)) { restRequest.WithHeader("Accept", accept); } if (!string.IsNullOrEmpty(voice)) { restRequest.WithArgument("voice", voice); } restRequest.WithBody <Text>(text); restRequest.WithHeader("X-IBMCloud-SDK-Analytics", "service_name=text_to_speech;service_version=v1;operation_id=Synthesize"); result = new MemoryStream(restRequest.AsByteArray().Result); } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }
public SynthesizeWatsonVoice(TokenOptions options, string endpoint) { if (string.IsNullOrEmpty(options.IamApiKey) && string.IsNullOrEmpty(options.IamAccessToken)) { throw new ArgumentNullException(nameof(options.IamAccessToken) + ", " + nameof(options.IamApiKey)); } this.endpoint = endpoint; client = new WatsonHttpClient(endpoint); tokenManager = new TokenManager(options); }
public ConversationHelper(string username, string password, string workspaceId, bool useProxy, string proxyAddress, string proxyPort, string proxyUser, string proxyPassword) { this.username = username; this.password = password; this.workspaceId = workspaceId; _conversation = new ConversationService(username, password, ConversationService.CONVERSATION_VERSION_DATE_2017_05_26); if (useProxy) { WatsonHttpClient httpClient = new WatsonHttpClient( _conversation.Endpoint, username, password, NetworkHelper.ConstruirHttpClient(useProxy, proxyAddress, proxyPort, proxyUser, proxyPassword)); _conversation.Client = httpClient; } }