Spaces:
Sleeping
Sleeping
Wenhao Feng
commited on
Commit
·
629b906
1
Parent(s):
602262e
Add genre.py word_data.json
Browse files- data/genre/word_data.json +56 -0
- data_handlers/genre.py +47 -0
data/genre/word_data.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"id": "001",
|
| 4 |
+
"score": [
|
| 5 |
+
[[0.0, 0.22, 55], [0.22, 0.33, 0], [0.33, 0.54, 55], [0.54, 0.9, 58], [0.9, 0.96, 60], [0.96, 1.6, 58], [1.6, 2.0, 56], [2.0, 2.22, 0], [2.22, 2.51, 54], [2.51, 2.86, 58], [2.86, 3.05, 60], [3.05, 3.92, 60], [3.92, 5.52, 58]],
|
| 6 |
+
[[0.0, 0.2, 61], [0.2, 0.26, 61], [0.26, 0.52, 61], [0.52, 0.58, 60], [0.58, 0.77, 60], [0.77, 0.99, 56], [0.99, 1.58, 60], [1.58, 1.75, 58], [1.75, 2.05, 56], [2.05, 2.68, 55]],
|
| 7 |
+
[[0.0, 0.57, 0], [0.57, 0.75, 55], [0.75, 0.83, 55], [0.83, 0.9, 0], [0.9, 1.36, 58], [1.36, 1.54, 60], [1.54, 1.86, 60], [1.86, 2.09, 58], [2.09, 2.59, 56], [2.59, 2.96, 56], [2.96, 3.0, 0]],
|
| 8 |
+
[[0.0, 0.15, 59], [0.15, 0.49, 59], [0.49, 0.69, 60], [0.69, 1.02, 60], [1.02, 1.28, 62], [1.28, 1.58, 63], [1.58, 1.64, 63], [1.64, 3.05, 56], [3.05, 6.44, 0]]
|
| 9 |
+
],
|
| 10 |
+
"note_lyrics": [
|
| 11 |
+
["在", "SP", "午", "夜", "的", "街", "角", "SP", "点", "燃", "一", "支", "烟"],
|
| 12 |
+
["看", "霓", "虹", "把", "孤", "独", "拉", "得", "很", "长"],
|
| 13 |
+
["SP", "我", "们", "SP", "像", "破", "碎", "的", "镜", "子", "AP"],
|
| 14 |
+
["反", "射", "着", "不", "完", "整", "的", "谎", "AP"]
|
| 15 |
+
],
|
| 16 |
+
"genre": "Alternative Rock",
|
| 17 |
+
"super-genre": "Rock",
|
| 18 |
+
"gender": "male"
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"id": "002",
|
| 22 |
+
"score": [
|
| 23 |
+
[[0.0, 0.28, 58], [0.28, 0.41, 58], [0.41, 0.83, 65], [0.83, 1.13, 67], [1.13, 1.28, 65], [1.28, 1.81, 65], [1.81, 2.05, 63], [2.05, 2.39, 62], [2.39, 3.27, 62]],
|
| 24 |
+
[[0.0, 0.18, 60], [0.18, 0.4, 60], [0.4, 0.69, 58], [0.69, 1.03, 60], [1.03, 1.32, 60], [1.32, 1.37, 0], [1.37, 1.76, 60], [1.76, 1.97, 58], [1.97, 2.24, 56], [2.24, 2.87, 55], [2.87, 2.94, 0]],
|
| 25 |
+
[[0.0, 0.25, 0], [0.25, 0.44, 55], [0.44, 0.7, 62], [0.7, 0.94, 58], [0.94, 1.43, 60], [1.43, 1.55, 60], [1.55, 2.11, 59], [2.11, 2.17, 67], [2.17, 3.25, 65], [3.25, 3.32, 65]],
|
| 26 |
+
[[0.0, 0.33, 0], [0.33, 0.43, 55], [0.43, 0.8, 61], [0.8, 0.87, 58], [0.87, 1.36, 58], [1.36, 1.86, 54], [1.86, 2.26, 53], [2.26, 3.14, 55], [3.14, 4.63, 0]]
|
| 27 |
+
],
|
| 28 |
+
"note_lyrics": [
|
| 29 |
+
["霓", "虹", "闪", "烁", "的", "街", "角", "转", "身"],
|
| 30 |
+
["听", "见", "心", "跳", "在", "SP", "耳", "畔", "沸", "腾", "AP"],
|
| 31 |
+
["SP", "掌", "心", "藏", "着", "未", "说", "的", "星", "辰"],
|
| 32 |
+
["SP", "等", "一", "个", "眼", "神", "确", "认", "AP"]
|
| 33 |
+
],
|
| 34 |
+
"genre": "Asian Pop",
|
| 35 |
+
"super-genre": "Pop",
|
| 36 |
+
"gender": "female"
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"id": "003",
|
| 40 |
+
"score": [
|
| 41 |
+
[[0.0, 0.14, 55], [0.14, 0.31, 55], [0.31, 0.48, 55], [0.48, 0.74, 56], [0.74, 1.01, 52], [1.01, 1.15, 53], [1.15, 1.3, 56], [1.3, 1.46, 58], [1.46, 1.59, 60], [1.59, 2.12, 61], [2.12, 2.6, 0]],
|
| 42 |
+
[[0.0, 0.03, 0], [0.03, 0.15, 53], [0.15, 0.38, 54], [0.38, 0.41, 54], [0.41, 0.7, 56], [0.7, 0.98, 52], [0.98, 1.12, 54], [1.12, 1.43, 55], [1.43, 1.57, 60], [1.57, 2.15, 58], [2.15, 2.64, 0]],
|
| 43 |
+
[[0.0, 0.08, 56], [0.08, 0.29, 56], [0.29, 0.5, 56], [0.5, 0.72, 56], [0.72, 0.93, 52], [0.93, 1.07, 54], [1.07, 1.19, 56], [1.19, 1.37, 57], [1.37, 1.43, 60], [1.43, 1.96, 60]],
|
| 44 |
+
[[0.0, 0.28, 60], [0.28, 0.41, 60], [0.41, 0.59, 60], [0.59, 0.71, 58], [0.71, 0.75, 0], [0.75, 0.92, 56], [0.92, 1.02, 50], [1.02, 1.18, 53], [1.18, 1.73, 53], [1.73, 3.64, 0]]
|
| 45 |
+
],
|
| 46 |
+
"note_lyrics": [
|
| 47 |
+
["午", "夜", "琴", "键", "跳", "动", "着", "老", "故", "事", "AP"],
|
| 48 |
+
["SP", "左", "手", "低", "音", "像", "心", "跳", "不", "止", "AP"],
|
| 49 |
+
["右", "手", "指", "尖", "溜", "過", "即", "興", "的", "詩"],
|
| 50 |
+
["酒", "馆", "木", "地", "SP", "板", "在", "咯", "吱", "AP"]
|
| 51 |
+
],
|
| 52 |
+
"genre": "Classical Blues",
|
| 53 |
+
"super-genre": "Blues",
|
| 54 |
+
"gender": "male"
|
| 55 |
+
}
|
| 56 |
+
]
|
data_handlers/genre.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .base import MelodyDatasetHandler
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class Genre(MelodyDatasetHandler):
|
| 5 |
+
name = "genre"
|
| 6 |
+
|
| 7 |
+
def __init__(self, melody_type, *args, **kwargs):
|
| 8 |
+
import json
|
| 9 |
+
|
| 10 |
+
with open("data/genre/word_data.json", "r", encoding="utf-8") as f:
|
| 11 |
+
song_db = json.load(f)
|
| 12 |
+
song_db = {song["id"]: song for song in song_db} # id as major
|
| 13 |
+
self.song_db = song_db
|
| 14 |
+
|
| 15 |
+
def get_song_ids(self):
|
| 16 |
+
return list(self.song_db.keys())
|
| 17 |
+
|
| 18 |
+
def get_style_keywords(self, song_id):
|
| 19 |
+
genre = self.song_db[song_id]["genre"]
|
| 20 |
+
super_genre = self.song_db[song_id]["super-genre"]
|
| 21 |
+
gender = self.song_db[song_id]["gender"]
|
| 22 |
+
return (genre, super_genre, gender)
|
| 23 |
+
|
| 24 |
+
def get_phrase_length(self, song_id):
|
| 25 |
+
# Return the number of lyrics (excluding SP/AP) in each phrase of the song
|
| 26 |
+
song = self.song_db[song_id]
|
| 27 |
+
note_lyrics = song.get("note_lyrics", [])
|
| 28 |
+
|
| 29 |
+
phrase_lengths = []
|
| 30 |
+
for phrase in note_lyrics:
|
| 31 |
+
count = sum(1 for word in phrase if word not in ("SP", "AP"))
|
| 32 |
+
phrase_lengths.append(count)
|
| 33 |
+
|
| 34 |
+
return phrase_lengths
|
| 35 |
+
|
| 36 |
+
def iter_song_phrases(self, song_id):
|
| 37 |
+
segment_id = 1
|
| 38 |
+
song = self.song_db[song_id]
|
| 39 |
+
for phrase_score, phrase_lyrics in zip(song["score"], song["note_lyrics"]):
|
| 40 |
+
segment = {
|
| 41 |
+
"note_start_times": [n[0] for n in phrase_score],
|
| 42 |
+
"note_end_times": [n[1] for n in phrase_score],
|
| 43 |
+
"note_lyrics": [character for character in phrase_lyrics],
|
| 44 |
+
"note_midi": [n[2] for n in phrase_score],
|
| 45 |
+
}
|
| 46 |
+
yield segment
|
| 47 |
+
segment_id += 1
|