Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        public SaAudioDocument Clone()
        {
            var clone = new SaAudioDocument();

            clone.m_isForTmpOperation = m_isForTmpOperation;
            clone.DocVersion          = m_docVer;
            clone.Segments            = (SegmentData[])Segments.Clone();
            clone.AudioFile           = m_audioFile;
            clone.MD5HashCode         = m_MD5HashCode;
            clone.SpeakerName         = m_speakerName;
            clone.SpeakerGender       = m_serializedGender[0];
            clone.EthnologueId        = EthnologueId;
            clone.Region                = Region;
            clone.Country               = Country;
            clone.Family                = Family;
            clone.LanguageName          = LanguageName;
            clone.Dialect               = Dialect;
            clone.NoteBookReference     = NoteBookReference;
            clone.FreeFormTranslation   = FreeFormTranslation;
            clone.Transcriber           = Transcriber;
            clone.SADescription         = SADescription;
            clone.DataChunkSize         = DataChunkSize;
            clone.FormatTag             = FormatTag;
            clone.Channels              = Channels;
            clone.SamplesPerSecond      = SamplesPerSecond;
            clone.AverageBytesPerSecond = AverageBytesPerSecond;
            clone.BlockAlignment        = BlockAlignment;
            clone.BitsPerSample         = BitsPerSample;
            clone.SAFlags               = SAFlags;
            clone.RecordFileFormat      = RecordFileFormat;
            clone.RecordTimeStamp       = RecordTimeStamp;
            clone.RecordBandWidth       = RecordBandWidth;
            clone.RecordSampleSize      = RecordSampleSize;
            clone.NumberOfSamples       = NumberOfSamples;
            clone.SignalMax             = SignalMax;
            clone.SignalMin             = SignalMin;
            clone.SignalBandWidth       = SignalBandWidth;
            clone.SignalEffSampSize     = SignalEffSampSize;
            clone.CalcFreqLow           = CalcFreqLow;
            clone.CalcFreqHigh          = CalcFreqHigh;
            clone.CalcVoicingThd        = CalcVoicingThd;
            clone.CalcPercntChng        = CalcPercntChng;
            clone.CalcGrpSize           = CalcGrpSize;
            clone.CalcIntrpGap          = CalcIntrpGap;

            return(clone);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 /// ------------------------------------------------------------------------------------
 public SegmentData(SaAudioDocument owningAudioDoc)
 {
     SaAudioDocument = owningAudioDoc;
 }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes an object to read SA data from the SA database.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public bool Initialize(string audioFilePath, bool isForTmpOperation)
        {
            m_doc = SaAudioDocument.Load(audioFilePath, isForTmpOperation, true);

            if (m_doc != null)
            {
                ResetSegmentEnumerators();
                return(true);
            }

            try
            {
                using (var audioReader = new AudioReader())
                {
                    var result = audioReader.Initialize(audioFilePath);
                    if (result == AudioReader.InitResult.FileNotFound)
                    {
                        ShowWaveFileNotFoundMsg(audioFilePath);
                        return(false);
                    }

                    if ((result == AudioReader.InitResult.InvalidFormat))
                    {
                        var msg = LocalizationManager.GetString("Miscellaneous.Messages.DataSourceReading.InvalidWaveFileMsg",
                                                                "The file '{0}' is not a valid wave file.");

                        Utils.MsgBox(string.Format(msg, Utils.PrepFilePathForMsgBox(audioFilePath)));
                        return(false);
                    }

                    // If audio file is old SA format, then tell user to use SA 3.0.1 to convert first.
                    if (audioReader.IsOldSaFormat)
                    {
                        if (m_worker != null)
                        {
                            m_worker.ReportProgress(-1);
                        }

                        var msg = LocalizationManager.GetString(
                            "Miscellaneous.Messages.DataSourceReading.AudioFileNeedsConversionMsg",
                            "It appears the audio file '{0}' may have been created using an old version " +
                            "of Speech Analyzer. In order for {1} to read data associated with this audio " +
                            "file it must first be converted using Speech Analyzer 3.0.1.");

                        msg = string.Format(msg, audioFilePath, Application.ProductName);
                        using (var dlg = new DownloadSaDlg(msg))
                            dlg.ShowDialog();

                        return(false);
                    }

                    // Now try reading the companion transcription file again.
                    m_doc = SaAudioDocument.Load(audioFilePath, isForTmpOperation, false);
                    ResetSegmentEnumerators();
                }
            }
            catch (Exception e)
            {
                var msg = LocalizationManager.GetString(
                    "Miscellaneous.Messages.DataSourceReading.ErrorInitializingSaDocumentReaderMsg",
                    "Error initializing SA Document reader.");

                ErrorReport.ReportNonFatalExceptionWithMessage(e, msg);
                return(false);
            }

            return(true);
        }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// This is really necessary since the garbage collector should handle clearing
 /// memory. But this is provided so COM clients can force freeing some of the memory.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void Close()
 {
     m_doc = null;
 }