private static void DoCreateTasks(Configuration cfg, ILoggerFactory _loggerFactory) { IS3Client s3Client = serviceProvider.GetService <IS3Client>(); string dbFile = Path.Combine(cfg.outputPath, TASK_DB_FILE_NAME); Log.Information($"Store recognition tasks list into {dbFile}"); SkTaskDb taskDb = new SkTaskDb(dbFile, Log.Logger); RecognitionSpec rSpec = new RecognitionSpec() { LanguageCode = cfg.lang, ProfanityFilter = true, Model = cfg.model, LiteratureText = cfg.punctuation, PartialResults = false, //возвращать только финальные результаты false AudioEncoding = cfg.audioEncoding, SampleRateHertz = cfg.sampleRate }; SkRecognitionClient recognitionClient = new SkRecognitionClient(new Uri("https://stt.api.cloud.yandex.net:443"), cfg.folderId, cfg.iamToken, rSpec, _loggerFactory, taskDb); s3Client.ProcessBucket(cfg.bucket, recognitionClient); Log.Information($"Found {taskDb.Count} objects"); }
private static void DoTaskResults(Configuration cfg, ILoggerFactory _loggerFactory) { string dbFile = Path.Combine(cfg.outputPath, TASK_DB_FILE_NAME); Log.Information($"Read tasks results from {dbFile}"); SkTaskDb taskDb = new SkTaskDb(dbFile, Log.Logger); HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", cfg.iamToken); foreach (SkTaskModel task in taskDb.Tasks) { if (!taskDb.CheckCompleated(cfg, task)) { string taskResults = @"https://operation.api.cloud.yandex.net/operations/" + task.TaskId; var response = httpClient.GetStringAsync(taskResults).GetAwaiter().GetResult(); dynamic jsonResponse = JObject.Parse(response); if ((bool)jsonResponse.done) { string txtFile = taskDb.StoreResults(jsonResponse, cfg, task); Log.Information($"Task {task.TaskId} text sucessfully stored to {txtFile}"); } else { Log.Logger.Warning($"Task {task.TaskId} is not compleated"); } } else { Log.Logger.Warning($"Task {task.TaskId} already compleated"); } } }