%对语音信号进行截短的代码 %加矩形窗时的倒谱的代码 %加矩形窗时的复倒谱的代码

时间: 2023-06-14 14:06:57 浏览: 71
对语音信号进行截短的代码: ```python import librosa # load audio signal signal, sr = librosa.load('audio.wav') # set start and end time in seconds start_time = 1.0 end_time = 3.0 # convert to sample indices start_index = int(start_time * sr) end_index = int(end_time * sr) # extract the truncated signal truncated_signal = signal[start_index:end_index] ``` 加矩形窗时的倒谱的代码: ```python import numpy as np import librosa # load audio signal signal, sr = librosa.load('audio.wav') # set window size and hop length window_size = 1024 hop_length = 512 # apply rectangular window signal_windowed = signal * np.hamming(window_size) # calculate magnitude spectrum magnitude_spectrum = np.abs(librosa.stft(signal_windowed, n_fft=window_size, hop_length=hop_length)) # calculate power spectrum power_spectrum = magnitude_spectrum ** 2 # apply mel filterbank mel_basis = librosa.filters.mel(sr=sr, n_fft=window_size, n_mels=40) mel_spectrum = np.dot(mel_basis, power_spectrum) # calculate log mel spectrum log_mel_spectrum = librosa.power_to_db(mel_spectrum) # calculate cepstral coefficients cepstral_coefficients = librosa.feature.mfcc(S=log_mel_spectrum, n_mfcc=13) # apply lifter to cepstral coefficients lifter = 22 lifter_vector = 1 + (lifter / 2) * np.sin(np.pi * np.arange(cepstral_coefficients.shape[0]) / lifter) lifter_matrix = np.tile(lifter_vector[:, np.newaxis], (1, cepstral_coefficients.shape[1])) cepstral_coefficients_lifted = cepstral_coefficients * lifter_matrix ``` 加矩形窗时的复倒谱的代码: ```python import numpy as np import librosa # load audio signal signal, sr = librosa.load('audio.wav') # set window size and hop length window_size = 1024 hop_length = 512 # apply rectangular window signal_windowed = signal * np.hamming(window_size) # calculate magnitude spectrum magnitude_spectrum = np.abs(librosa.stft(signal_windowed, n_fft=window_size, hop_length=hop_length)) # calculate phase spectrum phase_spectrum = np.angle(librosa.stft(signal_windowed, n_fft=window_size, hop_length=hop_length)) # calculate power spectrum power_spectrum = magnitude_spectrum ** 2 # apply mel filterbank mel_basis = librosa.filters.mel(sr=sr, n_fft=window_size, n_mels=40) mel_spectrum = np.dot(mel_basis, power_spectrum) # calculate log mel spectrum log_mel_spectrum = librosa.power_to_db(mel_spectrum) # calculate cepstral coefficients cepstral_coefficients = librosa.feature.mfcc(S=log_mel_spectrum, n_mfcc=13) # calculate lifter lifter = 22 lifter_vector = 1 + (lifter / 2) * np.sin(np.pi * np.arange(cepstral_coefficients.shape[0]) / lifter) # apply lifter to cepstral coefficients lifter_matrix = np.tile(lifter_vector[:, np.newaxis], (1, cepstral_coefficients.shape[1])) cepstral_coefficients_lifted = cepstral_coefficients * lifter_matrix # apply inverse DCT to liftered cepstral coefficients cepstral_coefficients_lifted_idct = np.real(np.fft.ifft(cepstral_coefficients_lifted, axis=0)) # apply exponential to liftered cepstral coefficients cepstral_coefficients_lifted_exponential = np.exp(cepstral_coefficients_lifted_idct) # apply inverse Fourier transform to exponential of liftered cepstral coefficients cepstral_coefficients_lifted_exponential_ifft = np.fft.ifft(cepstral_coefficients_lifted_exponential, axis=0) # calculate real part of complex cepstral coefficients real_part = np.real(cepstral_coefficients_lifted_exponential_ifft) # calculate imaginary part of complex cepstral coefficients imaginary_part = np.imag(cepstral_coefficients_lifted_exponential_ifft) # combine real and imaginary parts to form complex cepstral coefficients complex_cepstral_coefficients = real_part + 1j * imaginary_part # apply Fourier transform to complex cepstral coefficients cepstral_coefficients_complex_fft = np.fft.fft(complex_cepstral_coefficients, axis=0) # calculate phase spectrum of complex cepstral coefficients phase_spectrum_complex_cepstral = np.angle(cepstral_coefficients_complex_fft) # calculate magnitude spectrum of phase spectrum of complex cepstral coefficients magnitude_spectrum_phase_spectrum_complex_cepstral = np.abs(librosa.stft(phase_spectrum_complex_cepstral, n_fft=window_size, hop_length=hop_length)) # calculate complex cepstral coefficients of phase spectrum of complex cepstral coefficients cepstral_coefficients_phase_spectrum_complex_cepstral = np.fft.ifft(np.log(magnitude_spectrum_phase_spectrum_complex_cepstral), axis=0) # apply exponential to complex cepstral coefficients of phase spectrum of complex cepstral coefficients cepstral_coefficients_phase_spectrum_complex_cepstral_exponential = np.exp(cepstral_coefficients_phase_spectrum_complex_cepstral) # apply Fourier transform to exponential of complex cepstral coefficients of phase spectrum of complex cepstral coefficients cepstral_coefficients_phase_spectrum_complex_cepstral_exponential_fft = np.fft.fft(cepstral_coefficients_phase_spectrum_complex_cepstral_exponential, axis=0) # calculate complex cepstral coefficients of phase spectrum of complex cepstral coefficients complex_cepstral_coefficients_phase_spectrum_complex_cepstral = np.real(cepstral_coefficients_phase_spectrum_complex_cepstral_exponential_fft) # calculate real cepstral coefficients of phase spectrum of complex cepstral coefficients real_cepstral_coefficients_phase_spectrum_complex_cepstral = np.real(np.fft.ifft(complex_cepstral_coefficients_phase_spectrum_complex_cepstral, axis=0)) # apply lifter to real cepstral coefficients of phase spectrum of complex cepstral coefficients lifter_phase_spectrum_complex_cepstral = 22 lifter_vector_phase_spectrum_complex_cepstral = 1 + (lifter_phase_spectrum_complex_cepstral / 2) * np.sin(np.pi * np.arange(real_cepstral_coefficients_phase_spectrum_complex_cepstral.shape[0]) / lifter_phase_spectrum_complex_cepstral) lifter_matrix_phase_spectrum_complex_cepstral = np.tile(lifter_vector_phase_spectrum_complex_cepstral[:, np.newaxis], (1, real_cepstral_coefficients_phase_spectrum_complex_cepstral.shape[1])) real_cepstral_coefficients_phase_spectrum_complex_cepstral_lifted = real_cepstral_coefficients_phase_spectrum_complex_cepstral * lifter_matrix_phase_spectrum_complex_cepstral # apply lifter to real cepstral coefficients lifter = 22 lifter_vector = 1 + (lifter / 2) * np.sin(np.pi * np.arange(cepstral_coefficients.shape[0]) / lifter) lifter_matrix = np.tile(lifter_vector[:, np.newaxis], (1, cepstral_coefficients.shape[1])) cepstral_coefficients_lifted = cepstral_coefficients * lifter_matrix # combine real cepstral coefficients and real cepstral coefficients of phase spectrum of complex cepstral coefficients combined_cepstral_coefficients = np.concatenate((cepstral_coefficients_lifted, real_cepstral_coefficients_phase_spectrum_complex_cepstral_lifted), axis=0) ```

相关推荐

最新推荐

recommend-type

基于Android Studio的个人记账应用帮助用户轻松管理和跟踪他们的财务源码.zip

基于Android Studio的个人记账应用帮助用户轻松管理和跟踪他们的财务源码.zip基于Android Studio的个人记账应用帮助用户轻松管理和跟踪他们的财务源码.zip基于Android Studio的个人记账应用帮助用户轻松管理和跟踪他们的财务源码.zip基于Android Studio的个人记账应用帮助用户轻松管理和跟踪他们的财务源码.zip基于Android Studio的个人记账应用帮助用户轻松管理和跟踪他们的财务源码.zip基于Android Studio的个人记账应用帮助用户轻松管理和跟踪他们的财务源码.zip基于Android Studio的个人记账应用帮助用户轻松管理和跟踪他们的财务源码.zip基于Android Studio的个人记账应用帮助用户轻松管理和跟踪他们的财务源码.zip基于Android Studio的个人记账应用帮助用户轻松管理和跟踪他们的财务源码.zip基于Android Studio的个人记账应用帮助用户轻松管理和跟踪他们的财务源码.zip
recommend-type

基于python实现树莓派和传感器的植物生长环境评估信息系统

【作品名称】:基于python实现树莓派和传感器的植物生长环境评估信息系统 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【项目介绍】:基于python实现树莓派和传感器的植物生长环境评估信息系统
recommend-type

优质资源,Yearning Mysql SQL审核平台

Yearning Mysql SQL审核平台(使用go语言)
recommend-type

c语言课程设计-职工资源管理系统.rar

void displayMenu() { printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf("+ 职工资源管理系统 +\n"); printf("+ +\n"); printf("+ 1. 录入职工信息 +\n"); printf("+ 2. 显示全部职工信息 +\n"); printf("+ 3. 根据工号查询
recommend-type

华为OD机试D卷 - 来自异国的客人 - 免费看解析和代码.html

私信博主免费获取真题解析以及代码
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用 Python 画一个可以动的爱心

好的,我可以帮助您使用Python来绘制一个动态的爱心。您可以使用turtle库来实现。以下是实现代码: ```python import turtle import math # 设置画布和画笔 canvas = turtle.Screen() canvas.bgcolor("black") pencil = turtle.Turtle() pencil.speed(0) pencil.color("red", "pink") pencil.pensize(3) # 定义爱心函数 def draw_love(heart_size, x_offset=0, y_offset=0):
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。