2015-01-12 150 views
-2

我使用以下代码来提取音频文件的一些特征中,写他们在numpy的阵列文件: Python |类型错误:“NoneType”对象不是可调用

def calc_ceps(file_list, index, label, method=None, n_mfcc=None, s_rate=None):  
    '''Calculates and saves ceps''' 

    if method == None: 
     method = 'librosa' 
    if s_rate == None: 
     s_rate = 22050 
    if n_mfcc == None: 
     n_mfcc = 20  

    print 'Wave to Ceps:' 
    total = len(file_list)  

    for i, file in enumerate(file_list):   

     if method == 'librosa': 
      ceps = np.array(librosa.feature.mfcc(*read_wave(file), n_mfcc=n_mfcc)) 
      ceps.shape = (len(ceps[0]), n_mfcc) 

     elif method == 'talkbox': 
      ceps = mfcc(read_wave(file)[0])[0] 

     write_data('ceps', ceps, label[i], file) 
     progress(i, total) 

    progress(199, 199) 

功能进展(电流,总)打印进度,file_popul()提供文件列表和write_data()将numpy数组写入文件。

呼叫:

>>>get_ceps(*file_popul())() 

虽然calc_ceps()功能按预期工作100%(即节省了所有的文件它得到numpy的阵列),当它结束(即写入的所有文件)我得到以下回溯:

Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
TypeError: 'NoneType' object is not callable 

PDB输出与步骤:

>>> calc_ceps(*file_popul())()  
Wave to Ceps: 
99%> ~/final_project/code/utilities.py(122)calc_ceps() 
-> progress(199, 199) 
(Pdb) s 
--Call-- 
> ~/python/final_project/code/utilities.py(16)progress() 
-> def progress(current, maximum): 
(Pdb) s 
> ~/python/final_project/code/utilities.py(18)progress() 
-> ratio = round((float(current)/float(maximum)), 2) * 100 
(Pdb) s 
> ~/python/final_project/code/utilities.py(19)progress() 
-> if ratio < 100: 
(Pdb) s 
> ~/python/final_project/code/utilities.py(22)progress() 
-> elif ratio == 100: 
(Pdb) s 
> ~/python/final_project/code/utilities.py(23)progress() 
-> sys.stdout.write("\r100% done! \n") 
(Pdb) s 
100% done! 
--Return-- 
> ~/python/final_project/code/utilities.py(23)progress()->None 
->sys.stdout.write("\r100% done! \n") 
(Pdb) s 
--Return-- 
> ~/python/final_project/code/utilities.py(122)calc_ceps()->None 
-> progress(199, 199) 
(Pdb) s 
TypeError: "'NoneType' object is not callable" 
> <stdin>(1)<module>() 
(Pdb) s 
--Return-- 
> <stdin>(1)<module>()->None 
(Pdb) s 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: 'NoneType' object is not callable 
>>> 

使用python 2.7

在此先感谢。

编辑:注释掉progress()使用,这是我得到的pdb:

>>> calc_ceps(*file_enum())() 
Wave to Ceps: 
--Return-- 
> /home/mpir/python/final_project/code/utilities.py(121)calc_ceps()->None 
-> import pdb; pdb.set_trace() 
(Pdb) s 
TypeError: "'NoneType' object is not callable" 
> <stdin>(1)<module>() 
(Pdb) s 
--Return-- 
> <stdin>(1)<module>()->None 
(Pdb) s 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: 'NoneType' object is not callable 
>>> 

是不是很奇怪?

+1

你使用'progress'既作为一个函数名和作为变量? –

+0

不能:/。评论过“进度”部分,仍然有相同的错误 – Sotiris

回答

2

您calc_ceps函数没有return语句,所以calc_ceps(*file_popul())回报None,并尝试用一个更对大括号再次调用它:calc_ceps(*file_popul())()

+0

我觉得哑巴。谢谢 – Sotiris

相关问题