Ejemplo n.º 1
0
        private double[] GetChannelsEnergy(IList <FilterProcessResult> channelsSignal)
        {
            var    channelsRawEnergy = channelsSignal.Select(channel => SignalHelper.GetEnergy(channel.FilteredSignal, 0, channel.FilteredSignal.Length - 1));
            double maxEnergy         = channelsRawEnergy.Max(channel => Math.Abs(channel));

            return(channelsRawEnergy.Select(channelEnergy => channelEnergy / maxEnergy).ToArray());
        }
        public SignalContainer GetSpeech(SignalContainer rawSignal)
        {
            SignalContainer singal = rawSignal.Copy();

            singal.FrameSize  = 100; //ToDo! Constant change
            singal.FrameShift = singal.FrameSize;
            List <double> framesEnergy  = singal.GetFrames().Select(frame => SignalHelper.GetAverageEnergy(frame.Signal)).ToList();
            double        averageEnergy = framesEnergy.Average();

            double[]     flattenedFramesEnergy = ApplyMeanFilter(framesEnergy.ToArray(), 3);
            SpeechBounds speechFramesBounds    = GetSpeechBounds(flattenedFramesEnergy, averageEnergy);
            var          speechFrames          = singal.GetFrames().Skip(speechFramesBounds.Start).Take(speechFramesBounds.Width);

            double[] speechSignal = speechFrames.SelectMany(frame => frame.Signal).ToArray();
            return(new SignalContainer(speechSignal)
            {
                FrameSize = rawSignal.FrameSize,
                FrameShift = rawSignal.FrameShift
            });
        }