public static void Split(double myIntervalInSec, string path) { string outPutPath = Path.GetFullPath((Path.Combine(Path.Combine(path, @"..\")))); double interval = myIntervalInSec; TimeSpan totalDuration = WavSplitter.GetWavFileDuration(path); double a = totalDuration.TotalSeconds; double timeFromEnd = (totalDuration.TotalSeconds - interval); double timeFromStart = 0; TimeSpan start = TimeSpan.FromSeconds(timeFromStart); TimeSpan end = TimeSpan.FromSeconds(timeFromEnd); int i = 1; while (end.TotalSeconds > 0) { string outPutfilePath = outPutPath + "OutPut" + i + ".wav"; WavSplitter.TrimWavFile(path, outPutfilePath, start, end); timeFromEnd -= interval; timeFromStart += interval; end = TimeSpan.FromSeconds(timeFromEnd); start = TimeSpan.FromSeconds(timeFromStart); i++; //convert to flac string inputPath = outPutfilePath; string OutPutPath = @".\\"; ConvertWavToMono con = new ConvertWavToMono(inputPath, OutPutPath); con.Convert(); File.Delete(outPutfilePath); } }
/// <summary> /// Make Sure stopWordsFile is in the same place as file! /// </summary> public Video ConvertVideo(string filePath, string vidName, int filesParsed = 0) { m_FilesParsed = filesParsed; Dictionary <string, Dictionary <TimeSpan, string> > Sentences = new Dictionary <string, Dictionary <TimeSpan, string> >(); Dictionary <string, List <TimeInVid> > Terms = new Dictionary <string, List <TimeInVid> >(); if (!File.Exists(filePath)) { throw new ArgumentException(string.Format("File {0} not found!", filePath)); } VidToSoundConverter = new VideoToWavConverter(filePath, Path.GetDirectoryName(filePath)); // Convert video to audio: VidToSoundConverter.Convert(); string fullAudioPath = VidToSoundConverter.OutputFullPath; // Split audio: WavSplitter.Split(TimeIntervals, fullAudioPath); DirectoryInfo directory = new DirectoryInfo(Path.GetDirectoryName(filePath)); // Find all split files: FileInfo[] taskFiles = directory.GetFiles(OutputFilesFormat); TimeSpan toAddSpan = new TimeSpan(0, 0, TimeIntervals); TimeSpan start = new TimeSpan(0, 0, 0); TimeSpan end = start.Add(toAddSpan); for (int i = 0; i < m_FilesParsed; i++) { start = end; end = start.Add(toAddSpan); } for (int i = m_FilesParsed; i < taskFiles.Length; i++) { // find file #(i+1): string currentFile = directory.FullName + "\\" + OutputFilesFormat.Replace("*", (i + 1).ToString()); try { //string text = ApiClient.Convert(currentFile); string text = ApiGoogleCLient.Convert(currentFile); List <string> termsFound = Parser.Parse(text); foreach (string term in termsFound) { if (!Terms.ContainsKey(term)) { Terms.Add(term, new List <TimeInVid>()); } TimeInVid time = new TimeInVid(start, end); Terms[term].Add(time); MatchCollection matches = Regex.Matches(text, @"(?:\S+\s)?\S*(?:\S+\s)?\S*" + term + @"\S*(?:\s\S+)?\S*(?:\s\S+)?", RegexOptions.IgnoreCase); string sentence = matches[0].Value; if (!Sentences.ContainsKey(term)) { Sentences.Add(term, new Dictionary <TimeSpan, string>()); } Sentences[term].Add(time.Start, sentence); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { m_FilesParsed++; start = end; end = start.Add(toAddSpan); } } Video video = new Video(vidName); // Add Metadata video.Sentences = Sentences; video.Terms = Terms; return(video); }