【问题标题】:Linux command line / PHP bpm detectionLinux命令行/PHP bpm检测
【发布时间】:2012-02-03 20:42:30
【问题描述】:

我目前正在使用 getID3() 读取 mp3 标签数据,例如艺术家姓名、文件大小、持续时间等。当用户将文件上传到我的网站时,所有这些都会即时发生。

但是我想自动检测每首歌曲的 bpm 速度,以便将其保存到我的数据库中。

因此,简而言之,我正在寻找可以从 centOS 服务器运行的命令行实用程序或基于 php 的脚本,该脚本将获取 mp3 或 wav 文件,对其进行分析并将速度作为 bpm 返回。

我找到了 soundstretch,但它显然可以做到这一点,但由于某些原因似乎无法安装它。

有人有什么想法吗?

编辑:我终于成功安装了 soundtouch/soundstretch。

我想在我的 php 上传脚本中动态调用它们,以便可以将返回的 bpm 值添加到数据库中。

我尝试过没有成功...

$bpm = exec("soundstretch $filename -bpm");

假设变量 $bpm 现在将包含 bpm。我一定是误解了soundtouch的工作原理。不幸的是,文档很少。

我将如何收集返回的 bpm 并将其存储为变量以便将其保存到我的数据库中。

【问题讨论】:

  • "for some reason" ,你为什么不发布那个错误呢?
  • 从阅读看来,soundtouch/soundstretch 中的 bpm 检测充其量是不稳定的。我希望有人有其他建议。
  • 所有的 bpm 检测都是不稳定的,你所能做的就是少找一个。
  • 要点...我已经更新了我原来的问题,因为我已经成功安装了 soundtouch/soundstretch

标签: php linux centos soundtouch


【解决方案1】:

旧线程,但也许它可以帮助某人。

首先将 mp3 转换为 wav。我注意到它最适合它。似乎 soundstretch 不会将结果返回到 shell_exec 的结果中,所以我使用了一个附加文件。如果您比我更了解 linux,则可以做一些改进;-)。如果您需要一个接一个的曲目的 bpm,它可以工作。

// create new files, because we don't want to override the old files
$wavFile = $filename . ".wav";
$bpmFile = $filename . ".bpm";

//convert to wav file with ffmpeg
$exec = "ffmpeg -loglevel quiet -i \"" . $filename . "\" -ar 32000 -ac 1 \"" . $wavFile . "\"";
$output = shell_exec($exec);

// now execute soundstretch with the newly generated wav file, write the result into a file
$exec = "soundstretch \"" . $wavFile . "\" -bpm  2> " . $bpmFile;
shell_exec($exec);

// read and parse the file 
$output = file_get_contents($bpmFile);
preg_match_all("!(?:^|(?<=\s))[0-9]*\.?[0-9](?=\s|$)!is", $output, $match);

// don't forget to delete the new generated files
unlink($wavFile);
unlink($bpmFile);

// here we have the bpm
echo $match[0][2];

【讨论】:

    【解决方案2】:

    查看 deseven 的 php-bpm-detect,它是非常简单的 php 包装器,效果很好。您只需要安装 ffmpeg 和 soundstrech 依赖项:

    基本用法:

    $bpm_detect = new bpm_detect("file.mp3");  
    echo $bpm_detect->detectBPM(); 
    

    【讨论】:

      【解决方案3】:

      这是使用 SoundStretch 将 BPM 作为文本获取的 bash 命令行。

      soundstretch audio.wav -bpm 2>&1 | grep "Detected BPM" | awk '{print $4}'
      

      SoundStretch 使用stderr 而不是stdout 作为命令行输出。 您可以在他们的源代码(SoundStretch/main.cpp)中查看详细信息

      【讨论】:

        猜你喜欢
        • 2012-02-01
        • 2010-10-04
        • 1970-01-01
        • 2011-11-01
        • 2018-11-21
        • 1970-01-01
        • 1970-01-01
        • 2018-11-15
        相关资源
        最近更新 更多