コード例 #1
0
        /// ------------------------------------------------------------------------------------
        public bool Read(RecordCache recCache)
        {
            var reader = new SaAudioDocumentReader(m_worker);

            if (!reader.Initialize(m_dataSource.SourceFile) || reader.Words == null)
            {
                return(false);
            }

            // Make only a single record entry for the entire wave file.
            var recCacheEntry = new RecordCacheEntry(false, m_project)
            {
                DataSource       = m_dataSource,
                NeedsParsing     = false,
                Channels         = reader.Channels,
                BitsPerSample    = reader.BitsPerSample,
                SamplesPerSecond = reader.SamplesPerSecond,
            };

            var audioField = m_project.GetAudioFileField();

            recCacheEntry.SetValue(audioField.Name, m_dataSource.SourceFile);

            m_worker.ReportProgress(0);

            // Get all the record level fields.
            foreach (var fname in m_dataSource.FieldMappings.Where(m => !m.IsParsed).Select(m => m.Field.Name))
            {
                SetFieldValueFromObject(typeof(SaAudioDocumentReader), fname, reader, recCacheEntry.SetValue);
            }

            int wordIndex = 0;

            recCacheEntry.WordEntries = new List <WordCacheEntry>();
            foreach (var kvp in reader.Words)
            {
                var wentry = new WordCacheEntry(recCacheEntry, wordIndex++);

                foreach (var fname in m_dataSource.FieldMappings.Where(m => m.IsParsed).Select(m => m.Field.Name))
                {
                    SetFieldValueFromObject(typeof(AudioDocWords), fname, kvp.Value, wentry.SetValue);
                }

                wentry.AudioOffset = kvp.Key;
                wentry.AudioLength = kvp.Value.AudioLength;
                recCacheEntry.WordEntries.Add(wentry);
            }

            recCache.Add(recCacheEntry);
            return(true);
        }
コード例 #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads the transcription file for the specified audio file path.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static SaAudioDocument Load(string audioFilePath, bool isForTmpOperation,
                                           bool returnNullIfNoExist)
        {
            // Make sure the wave file exists.
            if (!File.Exists(audioFilePath))
            {
                SaAudioDocumentReader.ShowWaveFileNotFoundMsg(audioFilePath);
                return(null);
            }

            // Get what the file name should be for the transcription file.
            string transcriptionFile = GetTranscriptionFile(audioFilePath, isForTmpOperation);

            SaAudioDocument doc;

            // If it doesn't exist, it means the audio file doesn't have any transcriptions.
            if (!File.Exists(transcriptionFile))
            {
                if (returnNullIfNoExist)
                {
                    return(null);
                }

                doc = new SaAudioDocument(audioFilePath);
            }
            else
            {
                // Get the transcription data from the companion transcription file.
                Exception e;
                s_audioFileLoading = audioFilePath;
                doc = XmlSerializationHelper.DeserializeFromFile <SaAudioDocument>(transcriptionFile, out e);

                if (e != null)
                {
                    ErrorReport.ReportNonFatalException(e);
                    return(null);
                }

                s_audioFileLoading = null;
                doc.AudioFile      = audioFilePath;
            }

            doc.m_docVer            = kCurrSaDocVersion;
            doc.m_isForTmpOperation = isForTmpOperation;
            return(doc);
        }