public async Task StartTranscriptionAsync(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var busMessage    = JsonConvert.DeserializeObject <ServiceBusMessage>(Encoding.UTF8.GetString(message.Body));
            var audioFileName = StorageConnector.GetFileNameFromUri(busMessage.Data.Url);

            // Check if language identification is required:
            var secondaryLocale = StartTranscriptionEnvironmentVariables.SecondaryLocale;

            if (!string.IsNullOrEmpty(secondaryLocale) &&
                !secondaryLocale.Equals("None", StringComparison.OrdinalIgnoreCase) &&
                !secondaryLocale.Equals(Locale, StringComparison.OrdinalIgnoreCase))
            {
                secondaryLocale = secondaryLocale.Split('|')[0].Trim();

                Logger.LogInformation($"Primary locale: {Locale}");
                Logger.LogInformation($"Secondary locale: {secondaryLocale}");

                var languageID    = new LanguageIdentification(SubscriptionKey, SubscriptionRegion);
                var fileExtension = Path.GetExtension(audioFileName);
                var sasUrl        = StorageConnectorInstance.CreateSas(busMessage.Data.Url);
                var byteArray     = await StorageConnector.DownloadFileFromSAS(sasUrl).ConfigureAwait(false);

                var identifiedLocale = await languageID.DetectLanguage(byteArray, fileExtension, Locale, secondaryLocale).ConfigureAwait(false);

                Logger.LogInformation($"Identified locale: {identifiedLocale}");
                Locale = identifiedLocale;
            }

            await StartBatchTranscriptionJobAsync(new[] { message }, audioFileName).ConfigureAwait(false);
        }
예제 #2
0
        public bool CanTranslate(string text)
        {
            if (string.IsNullOrEmpty(text) || !_settings.IsTranslateEnabled)
            {
                return(false);
            }

            var language = LanguageIdentification.IdentifyLanguage(text);
            var split    = language.Split('-');

            var exclude = _settings.DoNotTranslate;

            if (exclude == null)
            {
                exclude = new[] { _settings.LanguagePackId };
            }

            foreach (var item in exclude)
            {
                var args = item.Split('_');
                if (string.Equals(args[0], split[0], StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            return(true);
        }