Exemplo n.º 1
0
 public TranscriptionService(IOptions <TranscriptionAccount> transcriptionAccount, HttpClient httpClient, IServiceHelpers helper)
 {
     _account    = transcriptionAccount.Value ?? throw new ArgumentNullException(nameof(transcriptionAccount));
     _helper     = helper ?? throw new ArgumentNullException(nameof(helper));
     _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
     _httpClient.DefaultRequestHeaders.Add("Authorization", _account.AuthToken);
 }
        public static IServiceCollection AddTranscription(
            this IServiceCollection services,
            Action <TranscriptionAccount> accountOptions)
        {
            var transcription = new TranscriptionAccount();

            accountOptions.Invoke(transcription);
            services.AddSingleton(transcription);
            services.AddSingleton(sp => new JsonSerializerOptions
            {
                Converters =
                {
                    new EnumConvertor <AcousticModelEnum>(),
                    new EnumConvertor <BoostParamEnum>()
                }
            });
            services.AddHttpClient <IServiceHelpers, ServiceHelper>();
            services.AddHttpClient <TranscriptionService>();
            return(services);
        }