我目前正在使用getID3()来读取mp3标签数据,例如艺术家姓名,文件大小,持续时间等。当用户将文件上传到我的网站时,所有这些都会立即发生。
但是我想自动检测每首歌曲的bpm速度,以便将其保存到我的数据库中。
所以简而言之,我正在寻找可以从centOS服务器运行的命令行实用程序或基于php的脚本,它将获取mp3或wav文件,分析它并将速度恢复为bpm。
我找到了soundstretch,但显然可以做到这一点,但由于某些原因似乎无法安装它。
有没有人有任何想法?
编辑:我终于成功安装了soundtouch / soundstretch。我想从我的php上传脚本中动态调用它们,以便可以将返回的bpm值添加到数据库中。
我试图跟随但没有成功......
$bpm = exec("soundstretch $filename -bpm");
假设变量$ bpm现在包含bpm。我必须误解soundtouch的工作原理。遗憾的是文档很少。
我如何收集返回的bpm并将其存储为变量以便将其保存到我的数据库中。
答案 0 :(得分:2)
旧帖子,但也许对某人有帮助。
首先将mp3转换为wav。我注意到它最适合它。似乎soundstretch没有将结果返回到shell_exec的resutl中,所以我正在使用一个额外的文件。如果你比我更了解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];
答案 1 :(得分:0)
通过deseven查看php-bpm-detect,这是非常简单的php包装,效果很好。您只需要安装ffmpeg和soundstrech dependecies:
基本用法:
$bpm_detect = new bpm_detect("file.mp3");
echo $bpm_detect->detectBPM();
答案 2 :(得分:0)
这是使用SoundStretch将BPM作为文本获取的bash命令行。
soundstretch audio.wav -bpm 2>&1 | grep "Detected BPM" | awk '{print $4}'
SoundStretch正在使用stderr
而不是stdout
作为命令行输出。
您可以在源代码中查看详细信息(SoundStretch / main.cpp)