如何使用Python和Gracenote识别音乐示例?

2024-06-07 21:00:04 发布

您现在位置:Python中文网/ 问答频道 /正文

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

但是文件很糟糕。

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

编辑:我真的想在Python中使用GNSDK。不要发表任何无关的文章,你会浪费时间的。


Tags: 文件文档数据库标题示例音乐sdk音频
3条回答

关键词:节拍频谱分析和节律检测。

这是一个众所周知的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)

但我不得不提的是,这个领域在计算机科学中是一个非常不成熟的领域,每一篇新的论文都是为了这个。所以,如果你也跟着学者们研究最近的发现,这对你会很有用。

添加:

Gracenote官方文档中提到的Web API包装: 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.

如果您不喜欢Ruby或Ruby on Rails,那么惟一的选择就是开发自己的Python包装器。

最后我使用了ACRCloud这个方法非常有效。似乎每个想使用Gracenote的人都会因为一些原因而回到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))

只需阅读标题问题,由于没有GNSDK的示例或教程,请尝试查看其他选项,
其中之一:

德哈武

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

似乎是对的。

相关问题 更多 >

    热门问题