Example #1
0
def test_mfcc_extractor():

  # get wave data
  wavData = stream.read(wavPath).value
  frames = stream.cut_frames(wavData)

  # define an input pipe
  pipe = base.PIPE() 
  for i in range(10):
    pipe.put( base.Packet( {"rawWave":frames[i*50:(i+1)*50]}, cid=i, idmaker=0 ) )

  pipe.stop()
  print( pipe.size() )

  # run a mfcc extractor
  extractor = feature.MfccExtractor(oKey="mfcc")

  extractor.start(inPIPE=pipe)
  extractor.wait()

  print( extractor.outPIPE.size() )
  packet = extractor.outPIPE.get()
  print( packet.keys() )
  print( packet.mainKey )
  print( packet["mfcc"].shape )
Example #2
0
def test_processor_cmvn():

  wavData = stream.read(wavPath).value
  frames = stream.cut_frames(wavData)

  pipe = base.PIPE() 

  for i in range(10):
    pipe.put( base.Packet( {"rawWave":frames[i*50:(i+1)*50]}, cid=i, idmaker=0 ) )

  pipe.stop()

  extractor = feature.MfccExtractor(minParallelSize=100,oKey="mfcc")
  processor = feature.MatrixFeatureProcessor(
                                    spliceLeft=3,
                                    spliceRight=3,
                                    cmvNormalizer=feature.FrameSlideCMVNormalizer(),
                                    oKey="mfcc",
                                  )

  extractor.start(inPIPE=pipe)
  processor.start(inPIPE=extractor.outPIPE,iKey="mfcc")
  processor.wait()

  print( processor.outPIPE.size() )
  packet = processor.outPIPE.get()
  print( packet.keys() )
  print( packet.mainKey )
  print( packet["mfcc"].shape ) # 273 = 13 * 3 * 7
Example #3
0
def test_mixture_feature_parallel():

    wavData = stream.read(wavPath).value
    frames = stream.cut_frames(wavData)

    pipe = base.PIPE()

    for i in range(10):
        pipe.put(
            base.Packet({"rawWave": frames[i * 50:(i + 1) * 50]},
                        cid=i,
                        idmaker=0))

    pipe.stop()

    extractor = feature.MixtureExtractor(mixType=["fbank", "mfcc"], )

    # Split packets
    def split_rule(items):
        return {"fbank": items["fbank"]}, {"mfcc": items["mfcc"]}

    spliter = joint.Spliter(split_rule, outNums=2)

    # use a processor to transform fbank feature
    processor1 = feature.MatrixFeatureProcessor(
        spliceLeft=2,
        spliceRight=2,
        cmvNormalizer=feature.FrameSlideCMVNormalizer(),
        oKey="fbank",
    )
    # use a processor to transform mfcc feature
    processor2 = feature.MatrixFeatureProcessor(
        spliceLeft=3,
        spliceRight=3,
        cmvNormalizer=feature.FrameSlideCMVNormalizer(),
        oKey="mfcc",
    )

    # combine packets
    def combine_rule(items):
        return {
            "feat": np.concatenate([items[0]["fbank"], items[1]["mfcc"]],
                                   axis=1)
        }

    combiner = joint.Combiner(combine_rule)

    extractor.start(inPIPE=pipe)
    spliter.start(inPIPE=extractor.outPIPE)
    processor1.start(
        inPIPE=spliter.outPIPE[0])  # specify which key you want to process
    processor2.start(
        inPIPE=spliter.outPIPE[1])  # specify which key you want to process
    combiner.start(inPIPE=[processor1.outPIPE, processor2.outPIPE])
    combiner.wait()

    print(combiner.outPIPE[0].size())
    packet = combiner.outPIPE[0].get()
    print(packet.keys())
    print(packet["feat"].shape)  # 211 = 120 + 91
Example #4
0
def test_functions():

    # Read wave info and data
    wav = stream.read(wavPath)
    print(wav.value)

    # Cut the stream into N frames (discard the rest)
    frames1 = stream.cut_frames(wav.value[:-10],
                                width=400,
                                shift=160,
                                snip=True)
    print(frames1.shape)

    # Cut the stream into N frames (retain the rest)
    frames2 = stream.cut_frames(wav.value[:-10],
                                width=400,
                                shift=160,
                                snip=False)
    print(frames2.shape)
Example #5
0
def test_mixture_feature_series():

    wavData = stream.read(wavPath).value
    frames = stream.cut_frames(wavData)

    pipe = base.PIPE()

    for i in range(10):
        pipe.put(
            base.Packet({"rawWave": frames[i * 50:(i + 1) * 50]},
                        cid=i,
                        idmaker=0))

    pipe.stop()

    extractor = feature.MixtureExtractor(mixType=["fbank", "mfcc"], )
    # use a processor to transform fbank feature
    processor1 = feature.MatrixFeatureProcessor(
        spliceLeft=2,
        spliceRight=2,
        cmvNormalizer=feature.FrameSlideCMVNormalizer(),
        oKey="fbank",
    )
    # use a processor to transform mfcc feature
    processor2 = feature.MatrixFeatureProcessor(
        spliceLeft=3,
        spliceRight=3,
        cmvNormalizer=feature.FrameSlideCMVNormalizer(),
        oKey="mfcc",
    )

    extractor.start(inPIPE=pipe)
    processor1.start(inPIPE=extractor.outPIPE,
                     iKey="fbank")  # specify which key you want to process
    processor2.start(inPIPE=processor1.outPIPE,
                     iKey="mfcc")  # specify which key you want to process
    processor2.wait()

    print(processor2.outPIPE.size())
    packet = processor2.outPIPE.get()
    print(packet.keys())
    print(packet["fbank"].shape)  # 120 = 24 * 5
    print(packet["mfcc"].shape)  # 91 = 13 * 7