public void ReadCues(string pathOfAudioFile) { try { if (Path.GetExtension(pathOfAudioFile).ToLower() == ".wav") { m_CueReader = new CueWaveFileReader(pathOfAudioFile); } } catch (Exception e) { MessageBox.Show(e.ToString()); } if (m_CueReader != null && m_CueReader.Cues != null) { int[] list = m_CueReader.Cues.CuePositions; m_CueLabelList = m_CueReader.Cues.CueLabels; int cueLabelCount = 0; m_CuePointsList = new List <double>(); foreach (int cuePoint in list) { int sampleRate = m_CueReader.WaveFormat.SampleRate; double tempCuePointInSec = (cuePoint / sampleRate) * 1000; m_CuePointsList.Add(tempCuePointInSec); cueLabelCount++; } } }
public void WriteCues(Dictionary <string, List <double> > DictionaryOfCuePoints, bool IsInsertCuePointsInBook = false) { string SourceFile = string.Empty; List <double> CuePoints = new List <double>(); int CuePointTime; string cueFileFolder = string.Empty; foreach (var entry in DictionaryOfCuePoints) { SourceFile = entry.Key; CuePoints = entry.Value; string sourceFileFolder = System.IO.Path.GetDirectoryName(SourceFile); string sourceFileName = System.IO.Path.GetFileName(SourceFile); string sourceFilePath = sourceFileFolder + "\\" + sourceFileName; cueFileFolder = sourceFileFolder + "\\" + "Audio_files_cuepoints"; if (!Directory.Exists(cueFileFolder)) { Directory.CreateDirectory(cueFileFolder); } string CueAudioFilePath = cueFileFolder + "\\" + "Cues_" + sourceFileName; CueWaveFileReader sourceStream = new CueWaveFileReader(SourceFile); using (CueWaveFileWriter writer = new CueWaveFileWriter(CueAudioFilePath, sourceStream.WaveFormat)) { AudioLibPCMFormat pcmFormat = new AudioLibPCMFormat((ushort)sourceStream.WaveFormat.Channels, (uint)sourceStream.WaveFormat.SampleRate, (ushort)sourceStream.WaveFormat.BitsPerSample); int BUFFER_SIZE = (int)pcmFormat.ConvertTimeToBytes(1500 * AudioLibPCMFormat.TIME_UNIT);//132300; byte[] buffer = new byte[BUFFER_SIZE]; int byteRead; writer.Flush(); while ((byteRead = sourceStream.Read(buffer, 0, buffer.Length)) > 0) { writer.Write(buffer, 0, byteRead); } foreach (double CuePoint in CuePoints) { CuePointTime = (int)CuePoint * sourceStream.WaveFormat.SampleRate; writer.AddCue(CuePointTime, string.Empty); } } if (IsInsertCuePointsInBook) { sourceStream.Dispose(); if (File.Exists(sourceFilePath)) { File.Delete(sourceFilePath); } File.Move(CueAudioFilePath, sourceFilePath); } } if (IsInsertCuePointsInBook && Directory.Exists(cueFileFolder)) { Directory.Delete(cueFileFolder); } }
private void m_btnBrowse_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Wave File (*.wav)|*.wav;"; if (open.ShowDialog() != DialogResult.OK) { return; } string fileName = open.FileName; var inPath = fileName; string outputFileName = fileName.Substring(0, fileName.Length - 4); var outPath = outputFileName + "Cue.wav"; //var reader = new AudioFileReader(inPath); CueWaveFileReader reader = new CueWaveFileReader(inPath); //var reader2 = new AudioFileReader(inPath); Cue cue = new Cue(9895490, "HI"); if (reader.Cues != null) { //reader.Cues.Add(cue); MessageBox.Show(reader.Cues.Count.ToString()); int[] list = reader.Cues.CuePositions; string[] cueLabelLists = reader.Cues.CueLabels; Console.WriteLine("List of cues {0}", list); int cueLabelCount = 0; foreach (int cuePoint in list) { decimal tempCuePointInSec = cuePoint / 44100; MessageBox.Show("Cue Point Position in seconds : " + tempCuePointInSec.ToString() + " and it's label is " + cueLabelLists[cueLabelCount]); cueLabelCount++; } //CueWaveFileWriter.CreateWaveFile(outPath, reader); } }