根据时间戳计算不同时间间隔的mfcc [英] compute mfcc for varying time intervals based on time stamps

查看:222
本文介绍了根据时间戳计算不同时间间隔的mfcc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个很棒的教程 https://github.com/manashmndl/DeadSimpleSpeechRecognizer 数据是根据由文件夹分隔的样本进行训练的,并且所有mfcc都将立即计算出来.

I came across this nice tutorial https://github.com/manashmndl/DeadSimpleSpeechRecognizer where the data is trained based on samples separated by folders and all mfcc are calculated at once.

我正在努力实现类似但又不同的目标.

I am trying to achieve something similar but in a different way.

基于此: https://librosa.github.io/librosa/generated/librosa.feature.mfcc.html

librosa可以为任何音频计算mfcc.如下:

librosa can compute mfcc for any audio. as follows :

import librosa  
y, sr = librosa.load('test.wav')
mymfcc= librosa.feature.mfcc(y=y, sr =sr)  

但是我想根据文件中的时间戳逐部分计算音频的mfcc.

but I want to calculate mfcc for the audio part by part based on timestamps from a file.

该文件具有如下标签和时间戳:

the file has labels and timestamps as follows :

0.0 2.0 sound1
2.0 4.0 sound2
4.0 7.0 silence
7.0 11.0 sound1

我想计算每个范围的mfcc,我希望得到看起来像mfcc及其相应标签的带标签的火车数据. mfcc_1,声音1 mfcc_2,声音2
等等.

I want to calculate mfcc of each range, my hope is to arrive at a labelled train data that looks like mfcc and its corresponding label. mfcc_1 , sound1 mfcc_2, sound2
and so on.

我该如何实现?

我查看了为基于注释的音频段生成mfcc文件,问题也很相似,但是我发现问题和答案都很难遵循(因为我对这个领域非常陌生).

I looked at generate mfcc's for audio segments based on annotated file , and question is similar but I found both the question and answer somewhat hard to follow (because I'm very new to this field).

TIA

更新:我的代码:

import librosa
from subprocess import call

def ListDir():
    call(["ls", "-l"])

def main():
    ListDir()
    readfile_return_segmentsmfcc()

my_segments =[]
# reading annotated file
def         readfile_return_segmentsmfcc():

    pat ='000.mp3'
    y, sr = librosa.load(pat)

    print "\n sample rate :"
    print sr

    with open("000.txt", "rb") as f:
        for line in f.readlines():
            start_time, end_time, label = line.split('\t')
            start_time = float(start_time)
            end_time = float(end_time)
            label = label.strip()
            my_segments.append((start_time, end_time, label))

            start_index = librosa.time_to_samples(start_time)
            end_index = librosa.time_to_samples(end_time)

            required_slice = y[start_index:end_index]
            required_mfcc = librosa.feature.mfcc(y=required_slice, sr=sr)
            print "Mfcc size is {} ".format(mfcc.shape)


            print start,end,label


    return my_segments


main()

推荐答案

  • 读取开始时间和结束时间:
    start=2.0 end=4.0

    • read the start and end times:
      start=2.0 end=4.0

      使用 librosa.time_to_samples :
      start_index = librosa.time_to_samples(start)
      end_index = librosa.time_to_samples(end)

      convert to samples index using librosa.time_to_samples:
      start_index = librosa.time_to_samples(start)
      end_index = librosa.time_to_samples(end)

      使用python [:]运算符从数据中获取相关的切片:
      slice = y[int(start_index):int(end_index)]

      use python [:] operator to get the relevant slice from data:
      slice = y[int(start_index):int(end_index)]

      slice上计算mfcc,等等.

      compute mfcc on slice, etc.

      这篇关于根据时间戳计算不同时间间隔的mfcc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆