栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

音频裁剪重新组合

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

音频裁剪重新组合

##将一段音频分割成几段,将这几段打乱顺序,然后重新组成音频。

import librosa
import random
import numpy as np
import os
import torch
import soundfile as sf

filelist = os.listdir(file_path)
for i in range(len(filelist)):    
    path = file_path +'/'+filelist[i] 
    out = out_path+'/'+ filelist[i].split('.')[0]+'s'+'.wav'
    print(path)
    y, sr = librosa.load(path, sr=16000, mono=True)
    duration = len(y) / sr
    
    window = int(0.1 * sr)
    L = list(range(window, len(y), window))
    
    print(L)
    result = []
    for i, cur in enumerate(L):
        input =y[cur-window:cur]
        if np.random.uniform(0,1) < 0.5:
            input = np.zeros_like(input)
        result.append(input)
    
    random.shuffle(result)
    random.shuffle(result)
    results = np.concatenate(result)
   
    sf.write(out , results, sr)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/588647.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号