Spaces:
Runtime error
Runtime error
File size: 2,083 Bytes
01c6887 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import numpy as np
import mido, os, pickle, yaml, argparse, math, librosa, hgtk, logging
from tqdm import tqdm
from pysptk.sptk import rapt
from typing import List, Tuple
from argparse import Namespace # for type
import torch
from typing import Dict
from meldataset import mel_spectrogram, spectrogram, spec_energy
from Arg_Parser import Recursive_Parse
def Convert_Feature_Based_Music(
music: List[Tuple[float, str, int]],
sample_rate: int,
frame_shift: int,
consonant_duration: int= 3,
equality_duration: bool= False
):
previous_used = 0
lyrics = []
notes = []
durations = []
for message_time, lyric, note in music:
duration = round(message_time * sample_rate) + previous_used
previous_used = duration % frame_shift
duration = duration // frame_shift
if lyric == '<X>':
lyrics.append(lyric)
notes.append(note)
durations.append(duration)
else:
lyrics.extend(Decompose(lyric))
notes.extend([note] * 3)
if equality_duration or duration < consonant_duration * 3:
split_duration = [duration // 3] * 3
split_duration[1] += duration % 3
durations.extend(split_duration)
else:
durations.extend([
consonant_duration, # onset
duration - consonant_duration * 2, # nucleus
consonant_duration # coda
])
return lyrics, notes, durations
def Expand_by_Duration(
lyrics: List[str],
notes: List[int],
durations: List[int],
):
lyrics = sum([[lyric] * duration for lyric, duration in zip(lyrics, durations)], [])
notes = sum([*[[note] * duration for note, duration in zip(notes, durations)]], [])
durations = [index for duration in durations for index in range(duration)]
return lyrics, notes, durations
def Decompose(syllable: str):
onset, nucleus, coda = hgtk.letter.decompose(syllable)
coda += '_'
return onset, nucleus, coda
|