我研究Python问题已经有一段时间了。我正在尝试使用Echoprint来整理我的音乐。所以我在为我写一些代码。
API是这样工作的:
但我正在写一个脚本,必须在“内部”执行这一任务。与前面一样,脚本应该获取文件并执行查找,并将结果输出到终端。(基本上-没有提供命令行参数)
那么,是否存在将文件传递到函数中的问题?我知道这听起来很傻,但这是一个我无法解决的问题。
如果我使用os.walk()等,它会将str对象作为参数返回给查找函数。我希望音频文件作为参数传递。
下面是将歌曲作为命令行arg的代码:
import sys
import os
import pyechonest.config as config
import pyechonest.song as song
config.CODEGEN_BINARY_OVERRIDE = os.path.abspath("/Users/******/python/minger/echoprint-codegen-master/echoprint-codegen")
config.ECHO_NEST_API_KEY='*****'
def lookup(file):
# Note that song.identify reads just the first 30 seconds of the file
fp = song.util.codegen(file)
if len(fp) and "code" in fp[0]:
# The version parameter to song/identify indicates the use of echoprint
result = song.identify(query_obj=fp, version="4.11")
print "Got result:", result
print result[0]
if len(result):
print "Artist: %s (%s)" % (result[0].artist_name, result[0].artist_id)
print "Song: %s (%s)" % (result[0].title, result[0].id)
else:
print "No match. This track may not be in the database yet."
else:
print "Couldn't decode", file
if __name__ == "__main__":
if len(sys.argv) < 2:
print >>sys.stderr, "Usage: %s <audio file>" % sys.argv[0]
sys.exit(1)
lookup(sys.argv[1])发布于 2014-02-22 08:14:34
从那里开始,http://echonest.github.io/remix/apidocs/pyechonest.util-module.html#codegen
您使用的方法有签名。
codegen(filename, start=0, duration=30)所以必须将文件名作为参数传递.不是文件本身..。
以前在这里使用过http://nullege.com/codes/show/src@p@y@pyechonest-7.1.0@pyechonest@song.py/371/util.codegen
if filename:
if os.path.exists(filename):
query_obj = util.codegen(filename, start=codegen_start, duration=codegen_duration)
if query_obj is None:
raise Exception("The filename specified: %s could not be decoded." % filename)https://stackoverflow.com/questions/21950628
复制相似问题