public void CreateVoiceSynthesis(string name, string description, string locale, string inputTextPath, Guid modelId)
 {
     Console.WriteLine("Creating batch synthesiss.");
     var properties = new Dictionary <string, string>
     {
         { "ConcatenateResult", "true" }
     };
     var model = ModelIdentity.Create(modelId);
     var voiceSynthesisDefinition = VoiceSynthesisDefinition.Create(name, description, locale, model, properties);
     var submitResponse           = VoiceAPIHelper.SubmitVoiceSynthesis(voiceSynthesisDefinition, inputTextPath, VoiceSynthesisUrl, this.subscriptionKey);
 }
Esempio n. 2
0
        public async Task <Uri> CreateVoiceSynthesis(string name, string description, string locale, string inputTextPath, Guid modelId, bool concatenateResult)
        {
            Console.WriteLine("Creating batch synthesiss.");
            var properties = new Dictionary <string, string>();

            if (concatenateResult)
            {
                properties.Add("ConcatenateResult", "true");
            }
            var model = ModelIdentity.Create(modelId);
            var voiceSynthesisDefinition = VoiceSynthesisDefinition.Create(name, description, locale, model, properties);

            using (var submitResponse = VoiceAPIHelper.SubmitVoiceSynthesis(voiceSynthesisDefinition, inputTextPath, VoiceSynthesisUrl, this.subscriptionKey))
            {
                return(await GetLocationFromPostResponseAsync(submitResponse).ConfigureAwait(false));
            }
        }
Esempio n. 3
0
        public void CreateBatchSynthesis(string name, string description, string locale, string inputTextPath, Guid modelId, string azureStorageConnectionString)
        {
            Console.WriteLine($"upload text to azure storage blob : {inputTextPath}");
            var containerName = "voicesynthesisinputfiles";

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(azureStorageConnectionString);
            var blobClient         = storageAccount.CreateCloudBlobClient();
            var containerReference = blobClient.GetContainerReference(containerName);

            containerReference.CreateIfNotExists();

            var fileName = $"SubscriptionKey_{Guid.NewGuid().ToString()}.txt";

            StorageHelper.UploadFileAsync(containerReference, fileName, inputTextPath);

            var textUrl = StorageHelper.GetBlobSas(blobClient, containerName, fileName, DateTime.MaxValue);


            Console.WriteLine("Creating batch synthesiss.");
            var model = ModelIdentity.Create(modelId);
            var batchSynthesisDefinition = BatchSynthesisDefinition.Create(name, description, locale, new Uri($"{ textUrl }"), model);
            var submitResponse           = VoiceAPIHelper.Submit <BatchSynthesisDefinition>(batchSynthesisDefinition, VoiceSynthesisUrl, this.subscriptionKey);
        }
        private async Task StartBatchTranscriptionJobAsync(IEnumerable <Message> messages, string jobName)
        {
            if (messages == null || !messages.Any())
            {
                Logger.LogError($"Invalid service bus message(s).");
                return;
            }

            var fetchingDelay      = GetInitialFetchingDelay(messages.Count());
            var locationString     = string.Empty;
            var serviceBusMessages = messages.Select(message => JsonConvert.DeserializeObject <ServiceBusMessage>(Encoding.UTF8.GetString(message.Body)));

            try
            {
                var properties = GetTranscriptionPropertyBag();

                var sasUrls        = new List <string>();
                var audioFileInfos = new List <AudioFileInfo>();

                foreach (var serviceBusMessage in serviceBusMessages)
                {
                    var sasUrl = StorageConnectorInstance.CreateSas(serviceBusMessage.Data.Url);
                    sasUrls.Add(sasUrl);
                    audioFileInfos.Add(new AudioFileInfo(serviceBusMessage.Data.Url.AbsoluteUri, serviceBusMessage.RetryCount));
                }

                ModelIdentity modelIdentity = null;

                if (Guid.TryParse(StartTranscriptionEnvironmentVariables.CustomModelId, out var customModelId))
                {
                    modelIdentity = ModelIdentity.Create(StartTranscriptionEnvironmentVariables.AzureSpeechServicesRegion, customModelId);
                }

                var transcriptionDefinition = TranscriptionDefinition.Create(jobName, "StartByTimerTranscription", Locale, sasUrls, properties, modelIdentity);

                var transcriptionLocation = await BatchClient.PostTranscriptionAsync(
                    transcriptionDefinition,
                    HostName,
                    SubscriptionKey,
                    Logger).ConfigureAwait(false);

                Logger.LogInformation($"Location: {transcriptionLocation}");

                var transcriptionMessage = new TranscriptionStartedMessage(
                    transcriptionLocation.AbsoluteUri,
                    jobName,
                    Locale,
                    modelIdentity != null,
                    audioFileInfos,
                    0,
                    0);

                await ServiceBusUtilities.SendServiceBusMessageAsync(FetchQueueClientInstance, transcriptionMessage.CreateMessageString(), Logger, fetchingDelay).ConfigureAwait(false);
            }
            catch (WebException e)
            {
                if (BatchClient.IsThrottledOrTimeoutStatusCode(((HttpWebResponse)e.Response).StatusCode))
                {
                    var errorMessage = $"Throttled or timeout while creating post. Error Message: {e.Message}";
                    Logger.LogError(errorMessage);
                    await RetryOrFailMessagesAsync(messages, errorMessage).ConfigureAwait(false);
                }
                else
                {
                    var errorMessage = $"Start Transcription in job with name {jobName} failed with WebException {e} and message {e.Message}";
                    Logger.LogError(errorMessage);

                    using (var reader = new StreamReader(e.Response.GetResponseStream()))
                    {
                        var responseMessage = await reader.ReadToEndAsync().ConfigureAwait(false);

                        errorMessage += "\nResponse message:" + responseMessage;
                    }

                    await WriteFailedJobLogToStorageAsync(serviceBusMessages, errorMessage, jobName).ConfigureAwait(false);
                }

                throw;
            }
            catch (TimeoutException e)
            {
                var errorMessage = $"Timeout while creating post, re-enqueueing transcription start. Message: {e.Message}";
                Logger.LogError(errorMessage);
                await RetryOrFailMessagesAsync(messages, errorMessage).ConfigureAwait(false);

                throw;
            }
            catch (Exception e)
            {
                var errorMessage = $"Start Transcription in job with name {jobName} failed with exception {e} and message {e.Message}";
                Logger.LogError(errorMessage);
                await WriteFailedJobLogToStorageAsync(serviceBusMessages, errorMessage, jobName).ConfigureAwait(false);

                throw;
            }

            Logger.LogInformation($"Fetch transcription queue successfully informed about job at: {jobName}");
        }