我正在做:
import librosa
D = librosa.stft(samples, n_fft=nperseg,
hop_length=overlap, win_length=nperseg,
window=scipy.signal.windows.hamming)
spect, _ = librosa.magphase(D)
audio_signal = librosa.griffinlim(spect, n_iter=1024,
win_length=nperseg, hop_length=overlap,
window=signal.windows.hamming)
print(audio_signal, audio_signal.shape)
sf.write('test.wav', audio_signal, sample_rate)
Run Code Online (Sandbox Code Playgroud)
并且它在重建的音频信号中引入了明显的失真。我能做些什么来改善它?
我正在使用两个不同的库来提取MFCC功能:
然而,两者的输出是不同的,甚至形状也不相同.这是正常的吗?还是有一个我缺少的参数?
我的代码的相关部分如下:
import bob.ap
import numpy as np
from scipy.io.wavfile import read
from sklearn import preprocessing
from python_speech_features import mfcc, delta, logfbank
def bob_extract_features(audio, rate):
#get MFCC
rate = 8000 # rate
win_length_ms = 30 # The window length of the cepstral analysis in milliseconds
win_shift_ms = 10 # The window shift of the cepstral analysis in milliseconds
n_filters = 26 # The number of filter bands
n_ceps = 13 # The number of cepstral …Run Code Online (Sandbox Code Playgroud) 假设我有单词“apple”,字母集 ['a', 'l', 'e'] 和重复次数 3。据此我想创建以下集合: ['aaapple' 、“aaappllle”、“aaappllleee”、“appllle”、“appllleee”、“appleee”]。
这是我已经尝试过的:
l = ['a', 'l', 'e']
word = "apple"
for i in range(0, len(l)):
print wordWithDuplicatedLetters = "".join(3*c if c == l[i] else c for c in word)
Run Code Online (Sandbox Code Playgroud)
但这并不匹配所有组合,并且 itertools 似乎没有提供我正在寻找的可能性。
我用简单的逻辑回归预测问题,并试图绘制precision_recall_curve和roc_curve用predict_proba(X_test)。我检查了文档字符串,predict_proba但没有太多关于它是如何工作的细节。我每次都输入错误并检查y_test,predict_proba(X_test)不匹配。最后发现predict_proba()产生 2 列,人们使用第二列。
如果有人可以解释它如何产生两列及其重要性,那将非常有帮助。TIA。
我想从字典创建一个数据框,其中的值是 2D numpy 数组。
my_Dict={'a': array([[1, 2, 3],[4, 5, 6]]), 'b': array([[7,8,9],[10,11,12]]),'c': array([[13,14,15],[16,17,18]])}
Run Code Online (Sandbox Code Playgroud)
我希望结果是一个包含 2 行(numpy 数组中的行数)和 3 列的数据框,如下所示:
a b c
0 [1, 2, 3] [7,8,9] [13,14,15]
1 [4, 5, 6] [10,11,12] [16,17,18]
Run Code Online (Sandbox Code Playgroud)
我尝试更改要列出的值并且它有效。但我想将这些值保留为 np 数组,以便将 numby 函数应用于这些值。
我有:
import librosa
from scipy import signal
import scipy.io.wavfile as sf
samples, sample_rate = sf.read(args.file)
nperseg = int(sample_rate * 0.001 * 20)
frequencies, times, spectrogram = signal.spectrogram(samples,
sample_rate,
nperseg=nperseg,
window=signal.hann(nperseg))
audio_signal = librosa.griffinlim(spectrogram)
print(audio_signal, audio_signal.shape)
sf.write('test.wav', audio_signal, sample_rate)
Run Code Online (Sandbox Code Playgroud)
然而,这会产生一个(接近)空的声音文件。
假设你有一个 python 类。我们就这样称呼它C。假设您在脚本中的某个位置或以交互模式创建了它的实例:c=C()
类中是否可以有一个“默认”方法,这样当您引用实例时,就会调用该默认方法?
class C(object):
def __init__(self,x,y):
self.x=x
self.y=y
def method0(self):
return 0
def method1(self):
return 1
def ...
...
def default(self):
return "Nothing to see here, move along"
Run Code Online (Sandbox Code Playgroud)
等等。
现在我以交互模式创建该类的实例,并引用它:
>>> c=C(3,4)
>>> c
<__main__.C object at 0x6ffffe67a50>
>>> print(c)
<__main__.C object at 0x6ffffe67a50>
>>>
Run Code Online (Sandbox Code Playgroud)
如果您单独引用该对象,是否可以有一个被调用的默认方法,如下所示?
>>> c
'Nothing to see here, move along'
>>> print(c)
Nothing to see here, move along
>>>
Run Code Online (Sandbox Code Playgroud) 我有点难以理解 MFCC。
从我读到的 mel 滤波器组应该是一系列三角形,它们变得更宽并且它们的峰值在同一个地方。像这样...
但是,当我使用 librosa 计算 mel 滤波器组时,我得到...
代码:
import librosa
import matplotlib.pyplot as plt
sr = 16000
mel_basis = librosa.filters.mel(sr=sr, n_fft=512, n_mels=10,fmin=0, fmax=sr / 2)
plt.plot(mel_basis)
Run Code Online (Sandbox Code Playgroud) 我有以下清单
list1 = [[x1,1,b1],[x2,1,b1],[x3,1,b1],[x4,1,b1]]
Run Code Online (Sandbox Code Playgroud)
和以下
list2 = [[x1,0,b1],[x5,0,b1],[x2,0,b1],[x7,0,b1]]
Run Code Online (Sandbox Code Playgroud)
我不知道如何创建最终列表,例如
list3 = [[x1,1,b1],[x2,1,b1],[x3,1,b1],[x4,1,b1],[x5,0,b1],[x7,0,b1]]
Run Code Online (Sandbox Code Playgroud)
仅当list1中不存在list2 [0] [0]元素时,才保留第一个list1并从list2添加到list1元素
我尝试了以下几种组合方式
for i in list1:
for i2 in list2:
if i[0][0] != i2[0][0]
list3.append(i2)
Run Code Online (Sandbox Code Playgroud)
但是list3显示常见的元素
我想在我的文档中创建多个列。
在全球范围内,我想做一些与此主页类似的事情,其中有 3 列:一列是当前版本,一列是新闻和更新,以及基本信息。
当我在 google 上搜索 Sphinx 中的多列时,我发现将列表分成 2 列,这不是我的情况
在维基上,我发现多列的唯一内容是表格,但我认为这不适用于这里?
这在使用 Sphinx 的 rst 文件中是可能的吗?
非常感谢
解析csv文件后,我从以下行之一获取此列表:
['', 'value1', '346.897', '', 'value2', '202.306', 'value3', '136.880', 'value4', '7.711', '']
Run Code Online (Sandbox Code Playgroud)
结果,我需要获得:
{
'value1': 346.897,
'value2': 202.306,
...
}
Run Code Online (Sandbox Code Playgroud)
有谁知道如何使其美丽?不使用索引。
现在,我从列表中删除所有空字符串,然后使用[0]like key和[1]like value等元素。
Variables :value1 # ... - are dynamic
Run Code Online (Sandbox Code Playgroud) Essentially, I am trying to make a function which reads an array, and a number. If the number is within the array, it should return True, and False otherwise. However, I find that for each element in the array there is a True or False - the code checks everything individually, when I only need one True or False; is the number in the array or not ?
def is_it_there(arr, k):
for x in arr:
if x == …Run Code Online (Sandbox Code Playgroud) 我必须创建一个函数,该函数接受一个上限列表并返回一个列表,其中包含所有可能的组合,直到上限。例如,输入列表[1,1,2]将产生:
[ [ 0 , 0 , 0 ] ,
[ 0 , 0 , 1 ] ,
[ 0 , 0 , 2 ] ,
[ 0 , 1 , 0 ] ,
[ 0 , 1 , 1 ] ,
[ 0 , 1 , 2 ] ,
[ 1 , 0 , 0 ] ,
[ 1 , 0 , 1 ] ,
[ 1 , 0 , 2 ] ,
[ 1 , 1 , 0 …Run Code Online (Sandbox Code Playgroud) python ×12
list ×4
librosa ×3
dictionary ×2
mfcc ×2
class ×1
matplotlib ×1
methods ×1
python-3.x ×1
scikit-learn ×1
scipy ×1
soundfile ×1
spectrogram ×1
speech ×1
string ×1
voice ×1