openSMILE批处理

Win10   openSMILE2.3.0

选择openSMILE处理音频,只是看到关于speech emtion recognition论文中大多使用该工具,所以起步先尝试使用该工具。

按照openSMILE-book 中步骤使用VS2010编译未果,奈何自己cpp学得不咋地,调试摸不到头脑,希望大神可以给出相应教程。

编译也不过是编译出一个友好的UI界面,不编译也并不影响使用,于是我选择在cmd下采用命令行的形式执行。单个音频处理可以参考http://blog.csdn.net/jaster_wisdom/article/details/56849291

然后我使用python调用cmd去进行的批处理,当然,你也可以直接写一个bat文件。下面这段代码只是示范,可以根据自己音频的存储形式自行调整。

# -*- coding: utf-8 -*-
"""
Created on Tue Nov 28 22:50:01 2017

@author: jackherrick
"""
import os
from subprocess import call
#sunprocess  is used for replacing other functions ex. os.system os.popen……
import time

#path constants
pathExecute = "C:\\Users\\jackherrick\\Desktop\\openSMILE\\opensmile\\opensmile-2.3.0\\"
pathExcuteFile = pathExecute + "bin\\Win32\\" + "SMILExtract_Release"
pathConfig = pathExecute + "config\\" + "IS09_emotion.conf"
pathAudioRoot = "C:\\Users\\jackherrick\\Documents\\MyCode\\liuchanhg\\"
pathOutputRoot = "C:\\Users\\jackherrick\\Documents\\MyCode\\testData\\" 

#the founction of excuting command
def excuteCMD(_pathExcuteFile,_pathConfig,_pathAudio,_pathOutput):
    cmd = _pathExcuteFile + " -C "+ _pathConfig +" -I "+ _pathAudio + " -O " + _pathOutput   
    call(cmd,shell=True)
#   subprocess.popen(cmd, shell=True)    
#  it's parallel computing,  while call is serial computing   

#the founction of looping OuterLayer(include looping SecondLevel)
def loopExcuteOuterLayer(_pathExcuteFile,_pathConfig,_pathAudioRoot,_pathOutputRoot):
    flag = -1
    for rt, dirs, files in os.walk(_pathAudioRoot):
        if os.path.isdir(rt):
            if flag == -1:
                listDirlist = dirs
            else:
                _pathOutputRootSecond = os.path.join(_pathOutputRoot,listDirlist[flag])
                _pathAudioRootSecond = os.path.join(_pathAudioRoot,listDirlist[flag])
                if not os.path.exists(_pathOutputRootSecond):
                    os.mkdir(_pathOutputRootSecond)
                loopExcuteInnerLayer(_pathExcuteFile,_pathConfig,_pathAudioRootSecond,_pathOutputRootSecond)
            flag = flag + 1
        
#the founction of looping InnerLayer
def loopExcuteInnerLayer(_pathExcuteFile,_pathConfig,_pathAudioRoot,_pathOutputRoot):
    for i in os.listdir(_pathAudioRoot):
        nameBehind =  os.path.splitext(i)[1]
        nameFront = os.path.splitext(i)[0]
        if nameBehind =='.wav':
            print(i)
            _pathOutput = os.path.join(_pathOutputRoot, nameFront+".txt")
            _pathAudio = os.path.join(_pathAudioRoot, i)
            excuteCMD(_pathExcuteFile,_pathConfig,_pathAudio,_pathOutput)
 
           
if __name__ == '__main__':
    time1 = time.time()
    loopExcuteOuterLayer(pathExcuteFile, pathConfig, pathAudioRoot, pathOutputRoot)
    time2 = time.time()A

 

posted @ 2017-11-29 12:07  herrcik  阅读(2083)  评论(2编辑  收藏  举报