2012-01-06 126 views
0

我目前使用getID3()来读取mp3标签数据,例如艺术家姓名,文件大小,持续时间等。当用户将文件上传到我的网站时,所有这些都会发生。Linux命令行/ PHP bpm检测

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

所以简而言之,我正在寻找一个可以从centOS服务器运行的命令行实用程序或基于php的脚本,它将采用mp3或wav文件,分析它并以bpm形式返回节奏。

我已经找到了声音,但它可以显然这样做,但由于某些原因似乎无法得到它安装。

有没有人有任何想法?

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

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

我曾尝试没有成功以下...

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

假设变量$ BPM现在将包含BPM。我必须误解soundtouch的工作原理。不幸的是文档很少。

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

+1

“出于某些原因”,为什么不发布那个错误呢? – 2012-01-06 02:09:49

+0

从阅读中可以看出,soundtouch/soundstretch中的bpm检测效果最好。我希望有人提出一些其他建议。 – gordyr 2012-01-06 02:12:35

+1

所有的bpm检测都是一片混乱,你所能做的就是找到一个少的吸。 – 2012-01-06 02:21:13

回答

2

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

首先将mp3转换为wav。我注意到它最适合它。似乎声音不会将结果返回到shell_exec的resute中,所以我使用了一个额外的文件。如果你知道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]; 
0

检查由deseven出来php-bpm-detect,这是非常简单的PHP的包装和伟大工程。你只需要安装的ffmpeg和soundstrech依赖条件:

基本用法:

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

这里是bash命令行来获得BPM与SoundStretch文本。

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

SoundStretch使用stderr代替stdout作为命令行输出。 你可以在他们的源代码中检查细节(SoundStretch/main.cpp)