[Audio processing] 数据集生成 & 性别年龄分类训练

Posted 小尾巴君

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Audio processing] 数据集生成 & 性别年龄分类训练相关的知识,希望对你有一定的参考价值。

1、重命名,Python中文路径各种错误,所以需要先将所有文件的路径名全都改成中文。用的是MAC系统,所以WIN下的命令行批处理没法解决,所以用C来完成

技术分享
//  Created by Carl on 16.
//  Copyright (c) 2016年 Carl. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
using namespace std;

void getFileList()
{
    string sourceDir = "/Users/karl/Work/database/rawdata/children_CN/";
    string targetDir = "/Users/karl/Work/database/rawdata/children/";
    DIR *dir;
    struct dirent *ptr;
    int i = 0;
    if ((dir=opendir(sourceDir.c_str())) == NULL)
    {
        perror("Open dir error...");
        exit(1);
    }
    while ((ptr=readdir(dir)) != NULL)
    {
        if(strcmp(ptr->d_name,".")==0 || strcmp(ptr->d_name,"..")==0)    ///current dir OR parrent
            continue;
        else if(ptr->d_type == 8)
        {
            printf("%s %s\n",(sourceDir + ptr->d_name).c_str(),(targetDir + to_string(i) + ".wav").c_str());
            if(rename((sourceDir + ptr->d_name).c_str(), (targetDir + to_string(i++) + ".wav").c_str())<0)
                cout<<"error"<<endl;
            else
                cout<<"ok"<<endl;
        }
        
    }
    return;
}

int main() {
    getFileList();
    return 1;
}
View Code

2、然后再使用FFMPEG那篇文章写的Python代码,将所有音频文件转成统一格式

技术分享
#coding=utf-8
#!/usr/bin/env python
‘‘‘CREATED:2016-03-08
Use example of ffmpeg
‘‘‘
import argparse
import sys
import os
import string
import subprocess as sp

#Full path of ffmpeg
FFMPEG_BIN = "/Users/karl/Documents/python/audio/tool/ffmpeg"
#Full path of sourceDir
sourceDir = "/Users/karl/Work/database/rawdata/male/"
#Full path of targetDir
targetDir = "/Users/karl/Work/database/age/male/"
#Channel setting 1 for mono
ac = 1
#Sample frequency
sf = 16000
#Extension setting
ext = wav

def convert(sourceDir, targetDir, ac, sf, ext):
    i = 0
    if not os.path.exists(targetDir):
        os.mkdir(targetDir)
    files = os.listdir(sourceDir)
    for f in files:
        if f.endswith(.wav):
            command = [ FFMPEG_BIN,
                       -i, os.path.join(sourceDir, f),
                       -ac, str(ac),
                       -ar, str(sf), os.path.join(targetDir, str(i) + "." + ext)]
            i += 1
            print command
            pipe = sp.Popen(command, stdout = sp.PIPE, bufsize = 10**8)

if __name__ == __main__:
    convert(sourceDir, targetDir, ac, sf, ext)
View Code

 

以上是关于[Audio processing] 数据集生成 & 性别年龄分类训练的主要内容,如果未能解决你的问题,请参考以下文章

[Audio processing] FFMPEG转音频格式和采样率

[Audio processing] wav音频文件读取int和double数组的关系

文献学习Deep Learning for Audio Signal Processing

文献学习Deep Learning for Audio Signal Processing

Audio Loop Processing.org(Java/Minim 声音库)

paper学习MapReduce:SimplIFied Data Processing on Large Clusters