小编tom*_*omm的帖子

如何正确使用pitch_shift(librosa)?

我尝试使用librosa 中的librosa 和pitch_shift。我录制了一些声音并使用了以下代码:

sampling_rate= 44100
y, sr = librosa.load(directory, sr=sampling_rate) # y is a numpy array of the wav file, sr = sample rate

y_shifted = librosa.effects.pitch_shift(y, sr, n_steps=4, bins_per_octave=24)  # shifted by 4 half steps
librosa.output.write_wav(directory, y_shifted, sr=sampling_rate, norm=False)
Run Code Online (Sandbox Code Playgroud)

它工作得很好 - 几乎。

我在新声音中听到一些噪音(在变调之后)

有什么我需要使用的东西吗?

不带平移:

https://vocaroo.com/i/s1qEEDvzcUHN

使用平移(n_steps = 4):

https://vocaroo.com/i/s0cOiC0cFJSB

python audio pitch-shifting librosa

1
推荐指数
1
解决办法
5981
查看次数

带有 .toml 配置和预提交钩子的 Flakehell

我正在尝试将 flakehell 作为预提交钩子运行。

我的 .pre-commit-config.yaml:

repos:
-   repo: local
    hooks:             
    -   id: flakehell
        name: flakehell
        entry: flakehell lint project/
        language: python
        pass_filenames: true
        stages: [push, commit]
        verbose: true
Run Code Online (Sandbox Code Playgroud)

pyproject.toml:

[tool.flakehell]
exclude = ["README.md"]
format = "colored"
show_source = true

[tool.flakehell.plugins]
flake8-bandit = ["+*", "-S322"]
flake8-bugbear = ["+*"]
flake8-builtins = ["+*"]
flake8-comprehensions = ["+*"]
flake8-darglint = ["+*"]
flake8-docstrings = ["+*"]
flake8-eradicate = ["+*"]
flake8-isort = ["+*"]
flake8-mutable = ["+*"]
flake8-pytest-style = ["+*"]
flake8-spellcheck = ["+*"]
mccabe = ["+*"]
pep8-naming = ["+*"] …
Run Code Online (Sandbox Code Playgroud)

python git pre-commit pre-commit.com

1
推荐指数
1
解决办法
487
查看次数

如何使用相同的参数正确调用多个函数?

我有一些问题:

如何使用相同的参数调用多个函数(10,100、1000 个函数)?

只是一个例子:

def function1(arg):
return arg

def function2(arg):
    return arg*2

def function_add_arg(arg):
    return np.sum(arg)


def call_functions(values):

    result = (function1(values), function2(values), function_add_arg(values))
    return result

values = [1, 2, 3, 4]
result_tuple = call_functions(values)
Run Code Online (Sandbox Code Playgroud)

如果我有 1000 个不同名称的函数怎么办?(Function_a, f2, add) 所以你不能使用:

result = (eval(f'function_{i}({values})') for i in range(100))
Run Code Online (Sandbox Code Playgroud)

我对这个例子的解决方案(它不是最好的,只是为了展示我的想法):

def call_functions(function_list, values):
    result = tuple((function(values) for function in function_list))
    return result

function_list = [function1, function2, function_add_arg]
values = [1, 2, 3, 4]

result_tuple = call_functions(function_list, values)
Run Code Online (Sandbox Code Playgroud)

但是怎么做才正确呢?(特别是如果我会调用更多函数)

不同的解决方案是使用 **kwargs 除了函数列表。

一些不同的、更好的解决方案?装饰者? …

python function

0
推荐指数
1
解决办法
146
查看次数