/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ private bool Initialize(string audioFilePath) { m_doc = SaAudioDocument.Load(audioFilePath, false, true); if (m_doc != null) { ResetSegmentEnumerators(); return(true); } try { using (AudioReader audioReader = new AudioReader()) { AudioReader.InitResult result = audioReader.Initialize(audioFilePath); if (result == AudioReader.InitResult.FileNotFound) { return(false); } if ((result == AudioReader.InitResult.InvalidFormat)) { return(false); } // Try reading data from older SA audio files, converting // it to Unicode along the way. if (!audioReader.Read(true)) { return(false); } // Now try reading the companion transcription file again. m_doc = SaAudioDocument.Load(audioFilePath, false, false); ResetSegmentEnumerators(); } } catch { return(false); } return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Converts the specified millisecond value to a byte offset used (and only understood /// by SA) for altered speed playback in SA. /// </summary> /// ------------------------------------------------------------------------------------ public static long MillisecondValueToBytes(long millisecondVal, string filename) { using (var reader = new AudioReader()) { if (reader.Initialize(filename) == AudioReader.InitResult.FileNotFound) { return(0); } // Assume the bytes per second is 44100, which it will be if the audio file // is not a wave file. long bytesPerSecond = 44100; if (reader.IsValidWaveFile()) { bytesPerSecond = reader.BytesPerSecond; } return((millisecondVal * bytesPerSecond) / 1000); } }