我试图使用此Python脚本比较声音,但是我可以找到上传它们的位置;和目标文件''''

发布于 2025-02-11 11:03:53 字数 795 浏览 0 评论 0原文

我是Python的新手,并且通常需要比较2个声音文件,而这个脚本似乎可以做到,但是我不知道如何将.Wav文件上传到此脚本,所以请帮助我

#!/usr/bin/python3
# compare.py
import argparse
from correlation import correlate

def initialize():
    parser = argparse.ArgumentParser()
    parser.add_argument("-i ", "--source-file", help="source file")
    parser.add_argument("-o ", "--target-file", help="target file")
    args = parser.parse_args()
  
    SOURCE_FILE = args.source_file if args.source_file else None
    TARGET_FILE = args.target_file if args.target_file else None
    if not SOURCE_FILE or not TARGET_FILE:
      raise Exception("Source or Target files not specified.")
    return SOURCE_FILE, TARGET_FILE
  
if __name__ == "__main__":
    SOURCE_FILE, TARGET_FILE = initialize()
    correlate(SOURCE_FILE, TARGET_FILE)

i'm new to python and to programming in general, i just need to compare 2 sound files and this script seems to do it but i can't figure out how to upload my .WAV files to this script so please help me

#!/usr/bin/python3
# compare.py
import argparse
from correlation import correlate

def initialize():
    parser = argparse.ArgumentParser()
    parser.add_argument("-i ", "--source-file", help="source file")
    parser.add_argument("-o ", "--target-file", help="target file")
    args = parser.parse_args()
  
    SOURCE_FILE = args.source_file if args.source_file else None
    TARGET_FILE = args.target_file if args.target_file else None
    if not SOURCE_FILE or not TARGET_FILE:
      raise Exception("Source or Target files not specified.")
    return SOURCE_FILE, TARGET_FILE
  
if __name__ == "__main__":
    SOURCE_FILE, TARGET_FILE = initialize()
    correlate(SOURCE_FILE, TARGET_FILE)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吾家有女初长成 2025-02-18 11:03:53

这看起来像是可以从命令行运行的程序。假设您已经安装了Python3,则可以启动它

python compare.py -h

,它将打印有关如何使用它的帮助消息。 compare.py.py 文件的目录。这是使用cd命令完成的)

(这要求您首先导航到包含在与compare.py.py的同一目录中,您可以简单地指定其名称:

python compare.py -i sourcefile.wav -o targetfile.wav

如果文件不在同一文件夹中,则应写入文件的完整路径。


关于术语的小评论:我不会将其称为上传将文件上传到脚本。您将所有内容都保留在计算机上,没有任何内容上传。您正在尝试将文件指定为命令行参数到python脚本。

This looks like a program that can be run from the command line. Assuming you already have python3 installed, you can launch it as

python compare.py -h

and it will print a help message on how to use it. (This requires you to first navigate to the directory that contains the compare.py file you showed us. That is done with the cd command)

If you place your two sound files in the same directory as the compare.py, you can simply specify their names:

python compare.py -i sourcefile.wav -o targetfile.wav

If the files are not in the same folder, you should write the full path of the files instead.


Minor Remark regarding Terminology: I wouldn't call it uploading the files to the script. You keep everything local on your computer, nothing is being uploaded. You are trying to specify the files as command line arguments to the python script.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文