async Task <int> OnExecute() { // get transcript _console.WriteLine("Getting transcription..."); var transcription = CallApi <Transcription>(() => _speechApi.GetTranscription(Guid.Parse(Id))); // read URLs (channels) foreach (var url in transcription.ResultsUrls) { (string text, string extension)output; using (var hc = new HttpClient()) { // download URLs var res = await hc.GetAsync(url.Value); if (res.IsSuccessStatusCode) { var rawContent = await res.Content.ReadAsStringAsync(); var convertedContent = SafeJsonConvert.DeserializeObject <TranscriptionResult>(rawContent); ITranscriptParser parser; switch (Format?.ToLower()) { case "vtt": parser = new VttTranscriptParser(); break; case "txt": parser = new TxtTranscriptParser(); break; case "json": default: parser = new JsonTranscriptParser(); break; } output = parser.Parse(convertedContent); // save to output if (!Directory.Exists(OutDir)) { Directory.CreateDirectory(OutDir); } var outputFileName = Path.Join(OutDir, (FileName ?? convertedContent.AudioFileResults[0].AudioFileName) + output.extension); File.WriteAllText(outputFileName, output.text); _console.WriteLine($"File {outputFileName} written."); } else { return(-1); } } } return(0); }
public void ParseTranscript_ReturnProperVtt_WithExtension() { // Arrange var rawData = File.ReadAllText("Data/transcript-result.json"); var tresult = JsonConvert.DeserializeObject <TranscriptionResult>(rawData); var parser = new VttTranscriptParser(); // Act var result = parser.Parse(tresult); // Asses Assert.Equal(".vtt", result.extension); Assert.Equal("WEBVTT\r\n\r\n00:00:03.920 --> 00:00:08.050\r\nTest.\r\n\r\n00:00:09.340 --> 00:00:13.790\r\nTest.\r\n\r\n", result.text); }