TIMIT数据集sphere格式转换为wav格式

使用python导入TIMIT的语音文件: 

wav_s=wavio.read("./datasets/timit/fdaw0/sa1.wav")

报错:

wave.Error: file does not start with RIFF id

或者其他报错:

ValueError: File format b'NIST'... not understood.

 

1、python 转换sphere格式为wav格式:(可行)

参考博客 : 

https://blog.csdn.net/zongza/article/details/85345498

使用python中的 sphfile库

#coding=utf-8
from sphfile import SPHFile
import glob
import os

if __name__ == "__main__":
    path = 'C:/Users/Administrator/Desktop/Experiment_python/datasets/timit/fcjf0/*.wav'
    sph_files = glob.glob(path)
    print(len(sph_files),"train utterences")
    for i in sph_files:
        sph = SPHFile(i)
        sph.write_wav(filename=i.replace(".wav","_n.wav"))
        # os.remove(i)    # 不用删除语音文件
    print("Completed")

效果:sa1_n.wav  sa2_n.wav 等是生成的wav格式文件。用python的wavio.read()函数可以正确读取。

19/11/06  转换多个文件夹下文件

sphere_convert.py 

# coding=utf-8

from sphfile import SPHFile
import glob
import os
import sys

if __name__ == "__main__":
    path = 'F:/Study/Speech Enhancement/SE-DNN-NMF/datasets/timit_clean_selected/train/dr1/'
    files = os.listdir(path)      #返回指定路径下的文件和文件夹列表
    print(files)
    for file in files:
        path_n = os.path.join(path, file)  # 连接两个或更多的路径名
        # print(path_n)
        path_ns = path_n+ "/" + "*.wav"
        print(path_ns)

        #file_n = os.listdir(path_n)     #返回指定路径下的文件和文件夹列表
        # print(file_n)

        # for i in file_n:      # 循环读取路径下的文件并筛选输出 (可行)
        #     if os.path.splitext(i)[1] == ".wav":  # 筛选 wav文件
        #         print(i)  # 输出所有的 wav文件
        # os.system("pause")

        sph_files = glob.glob(path_ns)      #返回所有匹配的文件路径列表
        print(len(sph_files), "train utterences")
        print(sph_files)
        # os.system("pause")

        for i in sph_files:
            sph = SPHFile(i)
            sph.write_wav(filename=i.replace(".wav", "_n.wav"))   #保存在源文件所在文件夹
            # os.remove(i)    # 不用删除语音文件
        print("Completed")
        # os.system("pause")

 

python和matlab 画语音波形图:

https://blog.csdn.net/qq_34638161/article/details/89604924

1-1、sph2pipe转换 (未成功)

https://www.cnblogs.com/JJJanepp/p/10432254.html

https://www.cnblogs.com/dream-and-truth/p/10413575.html

# https://www.cnblogs.com/JJJanepp/p/10432254.html
# https://www.cnblogs.com/dream-and-truth/p/10413575.html
# encoding="utf-8"
import os
import os.path

rootdir = "C:/Users/Administrator/Desktop/Experiment_python/datasets/timit/fcjf0"
timitpath = "C:/Users/Administrator/Desktop/Experiment_python/datasets/timit/fcjf0"
targetpath = "C:/Users/Administrator/Desktop/Experiment_python/datasets/timit_transfer"
sph2pipepath = "C:/Users/Administrator/Desktop/sph2pipe_v2.5/sph2pipe"
f = open('C:/Users/Administrator/Desktop/Experiment_python/datasets/make_sph2pipe_file.txt','w')
for root,dirs,files in os.walk(rootdir):
   for fn in files:
       if fn[len(fn)-3:len(fn)]=='wav':
           sourcefile = timitpath+root[len(rootdir):]+"/"+fn
           targetfile = targetpath + "/" + fn
           s = sph2pipepath + " -f wav " + sourcefile+" "+targetfile+"\n"
           f.write(s)
f.close()

在ubuntu下运行 sphere_script2.sh文件不成功:

2、matlab 转换sphere格式为wav格式: (可行)

      参考博客:  https://www.xuebuyuan.com/2053299.html

% 开头部分引入了部分噪声
% function wavdata=readTIMITwav(filepath) 

clc;
clear all;

filepath='C:\Users\Administrator\Desktop\Experiment_python\datasets\timit\fcjf0\sa1.wav';
fidin=fopen(filepath,'r');         % 打开文件,指定对该文件进行的操作方式为只读
fprintf('fidin:%f\n',fidin)       % 判断是否读取成功,-1不成功,正数代表成功
A = fread(fidin,inf,'int16');      % 以二进制形式读取文件的全部数据,精度为16位整型
wavdata=A./(2^15);                 % SPHERE 文件头1024字节,转换成wav格式

fs=16000;
size(wavdata)
wavdata=wavdata(600:end,1);        % 前面部分引入了噪声,去噪声,wavdata(513:end,1)
sound(wavdata,fs);
audiowrite('speech.wav',wavdata,fs); 
fclose(fidin);                      % 关闭文件

2-1、matlab转换 (未验证)

http://www.360doc.com/content/15/0325/15/13208159_457943855.shtml

step1  遍历文件夹,找出wav文件 find_wav.m

step2  文件转换conver_wav.m

step3  检查 check_wav.m

 

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值