當前位置: 首頁>>代碼示例>>Python>>正文


Python Extractor.get_zcr_moy方法代碼示例

本文整理匯總了Python中extractor.Extractor.get_zcr_moy方法的典型用法代碼示例。如果您正苦於以下問題:Python Extractor.get_zcr_moy方法的具體用法?Python Extractor.get_zcr_moy怎麽用?Python Extractor.get_zcr_moy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在extractor.Extractor的用法示例。


在下文中一共展示了Extractor.get_zcr_moy方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from extractor import Extractor [as 別名]
# 或者: from extractor.Extractor import get_zcr_moy [as 別名]
class Teacher:
    def __init__(self):
        self.model = SongModel()
        self.extractor = Extractor()

    def parse_set(self):
        content = []
        with open("training/Tracks/ground_truth.csv") as f:
            for l in f:
                l = l.replace('\"', '').replace('\n', '')
                name = ""
                genre = ""
                flag = 0
                for c in l:
                    if c == ',':
                        flag = 1
                    elif flag == 0:
                        name += c
                    elif flag == 1:
                        genre += c
                content.append([name, genre])
        return content

    def train(self):
        for item in self.parse_set():
            self.extractor.set_song(item[0])
            tempo = self.extractor.get_tempo()
            rolloffmoy = self.extractor.get_rolloff_moy()
            rolloffect = self.extractor.get_rolloff_ect()
            zcrmoy = self.extractor.get_zcr_moy()
            zcrect = self.extractor.get_zcr_ect()
            duration = self.extractor.get_duration()
            self.model.add(item[0], item[1], tempo, rolloffmoy, rolloffect, zcrmoy, zcrect, duration)
            print("ADDED : " + item[0] + " " + item[1] + " " + str(tempo) + " " + str(rolloffmoy) + " " + str(rolloffect) + " " + str(zcrmoy) + " " + str(zcrect) + " " + str(duration))
        print("DONE")
開發者ID:yrakcaz,項目名稱:music-style-classifier,代碼行數:37,代碼來源:teacher.py

示例2: __init__

# 需要導入模塊: from extractor import Extractor [as 別名]
# 或者: from extractor.Extractor import get_zcr_moy [as 別名]
class AI:
    def __init__(self, song):
        self.song = song
        self.model = SongModel()
        self.extractor = Extractor()
        self.tempo = 0
        self.rolloffmoy = 0.0
        self.rolloffect = 0.0
        self.zcrmoy = 0.0
        self.zcrect = 0.0
        self.duration = 0.0
        self.genre = []
        for l in open("training/Tracks/genres.txt"):
            self.genre.append(l.replace('\n',''))

    def get_song_datas(self):
        self.extractor.set_song(self.song)
        self.tempo = self.extractor.get_tempo()
        self.rolloffmoy = self.extractor.get_rolloff_moy()
        self.rolloffect = self.extractor.get_rolloff_ect()
        self.zcrmoy = self.extractor.get_zcr_moy()
        self.zcrect = self.extractor.get_zcr_ect()
        self.duration = self.extractor.get_duration()

    def classify_with_knn(self):
        vect, mat = self.model.get_datas()
        clf = neighbors.KNeighborsClassifier()
        clf.fit(mat, vect)
        self.get_song_datas()
        l = [[self.tempo, self.rolloffmoy, self.rolloffect, self.zcrmoy, self.zcrect, self.duration]]
        ret = clf.predict(l)
        print(self.genre[ret[0]])

    def classify_with_svm(self):
        vect, mat = self.model.get_datas()
        clf = svm.SVC(class_weight='auto', kernel='linear')
        clf.fit(mat, vect)
        self.get_song_datas()
        l = [[self.tempo, self.rolloffmoy, self.rolloffect, self.zcrmoy, self.zcrect, self.duration]]
        ret = clf.predict(l)
        print(self.genre[int(ret[0])])
開發者ID:yrakcaz,項目名稱:music-style-classifier,代碼行數:43,代碼來源:ai.py


注:本文中的extractor.Extractor.get_zcr_moy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。