如何使用 Python 和 Gracenote 识别音乐样本?

How to recognize a music sample using Python and Gracenote?

我最近发现GNSDK(Gracenote SDK)似乎提供了几种编程语言的示例,通过对它们进行指纹识别来识别音乐样本,然后请求他们的音频数据库以获取相应的艺术家和歌曲标题.

但是文档太糟糕了。

如何使用Python和GNSDK识别音频样本文件?提供的文档中没有任何示例或教程。

编辑: 我真的很想将 GNSDK 与 Python 一起使用。不要post任何无关的东西,你会浪费你的时间。

关键字是:节拍频谱分析和节奏检测。

这是一个众所周知的 Python 库,可以包含针对您的问题的解决方案: https://github.com/aubio/aubio

我还建议您查看此页面以了解其他库: https://wiki.python.org/moin/PythonInMusic

最后这个项目更 Python 友好的解决方案和简单的开始方式: https://github.com/librosa/librosa

来自 Librosa 的示例,用于计算歌曲的速度(每分钟节拍数):

# Beat tracking example
from __future__ import print_function
import librosa

# 1. Get the file path to the included audio example
filename = librosa.util.example_audio_file()

# 2. Load the audio as a waveform `y`
#    Store the sampling rate as `sr`
y, sr = librosa.load(filename)

# 3. Run the default beat tracker
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

print('Estimated tempo: {:.2f} beats per minute'.format(tempo))

# 4. Convert the frame indices of beat events into timestamps
beat_times = librosa.frames_to_time(beat_frames, sr=sr)

print('Saving output to beat_times.csv')
librosa.output.times_csv('beat_times.csv', beat_times)

但我不得不说,这个领域在计算机科学中是一个非常不成熟的领域,每一篇新论文都会出现。因此,如果您也关注学者的最新发现,这将对您有所帮助。

加法:

Web API Gracenote 官方文档中提到的包装器: https://developer.gracenote.com/web-api#python

对于Python:

https://github.com/cweichen/pygn

但是正如您所看到的,这个包装器没有很好的文档记录并且不成熟。因此,我建议您使用此 Ruby 包装器而不是 Python;

对于Ruby:

https://github.com/JDiPierro/tmsapi

require 'tmsapi'

# Create Instace of the API
tms = TMSAPI::API.new :api_key => 'API_KEY_HERE'

# Get all movie showtimes for Austin Texas
movie_showings = tms.movies.theatres.showings({ :zip => "78701" })

# Print out the movie name, theatre name, and date/time of the showing.
movie_showings.each do |movie|
  movie.showtimes.each do |showing|
    puts "#{movie.title} is playing at '#{showing.theatre.name}' at #{showing.date_time}."
  end
end

# 12 Years a Slave is playing at 'Violet Crown Cinema' at 2013-12-23T12:45.
# A Christmas Story is playing at 'Alamo Drafthouse at the Ritz' at 2013-12-23T16:00.
# American Hustle is playing at 'Violet Crown Cinema' at 2013-12-23T11:00.
# American Hustle is playing at 'Violet Crown Cinema' at 2013-12-23T13:40.
# American Hustle is playing at 'Violet Crown Cinema' at 2013-12-23T16:20.
# American Hustle is playing at 'Violet Crown Cinema' at 2013-12-23T19:00.
# American Hustle is playing at 'Violet Crown Cinema' at 2013-12-23T21:40.

如果您对 Rails 上的 Ruby 或 Ruby 不满意,那么唯一的选择是开发您自己的 Python 包装器。

只是阅读您的标题问题,因为没有 GNSDK 的示例或教程,请尝试查看其他选项,
一个:

dejavu

Audio fingerprinting and recognition algorithm implemented in Python, see the explanation here:

Dejavu can memorize audio by listening to it once and fingerprinting it. Then by playing a song and recording microphone input, Dejavu attempts to match the audio against the fingerprints held in the database, returning the song being played.

https://github.com/worldveil/dejavu

似乎是对的。

我最终使用了 ACRCloud,效果很好。

Python 例子:

from acrcloud.recognizer import ACRCloudRecognizer

config = {
    'host': 'eu-west-1.api.acrcloud.com',
    'access_key': 'access key',
    'access_secret': 'secret key',
    'debug': True,
    'timeout': 10
}

acrcloud = ACRCloudRecognizer(config)

print(acrcloud.recognize_by_file('sample of a track.wav', 0))

https://github.com/acrcloud/acrcloud_sdk_python