waytan22 commited on
Commit
0a1e140
·
1 Parent(s): 8e684f6

adapt lyrics input

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -4,6 +4,7 @@ import json
4
  import numpy as np
5
  from datetime import datetime
6
  import os
 
7
  import sys
8
  import librosa
9
  import time
@@ -23,7 +24,7 @@ EXAMPLE_DESC = """female, dark, pop, sad, piano and drums, the bpm is 125."""
23
  EXAMPLE_LYRICS = """
24
  [intro-short]
25
 
26
- [verse]
27
  夜晚的街灯闪烁.
28
  我漫步在熟悉的角落.
29
  回忆像潮水般涌来.
@@ -32,7 +33,7 @@ EXAMPLE_LYRICS = """
32
  那些曾经的甜蜜.
33
  如今只剩我独自回忆.
34
 
35
- [bridge]
36
  手机屏幕亮起.
37
  是你发来的消息.
38
  简单的几个字.
@@ -42,7 +43,7 @@ EXAMPLE_LYRICS = """
42
  我多想回到从前.
43
  重新拥有你的陪伴.
44
 
45
- [chorus]
46
  回忆的温度还在.
47
  你却已不在.
48
  我的心被爱填满.
@@ -55,22 +56,34 @@ R&B的节奏奏响.
55
  [outro-short]
56
  """.strip()
57
 
 
 
 
58
 
59
  # 模拟歌曲生成函数
60
  def generate_song(description, lyric, prompt_audio=None, cfg_coef=None, temperature=None, top_k=None, progress=gr.Progress(track_tqdm=True)):
61
  global model
62
  params = {'cfg_coef':cfg_coef, 'temperature':temperature, 'top_k':top_k}
63
  params = {k:v for k,v in params.items() if v is not None}
 
64
 
65
  # 生成过程
66
  print(f"Generating song with description: {description}")
67
  print(f"Lyrics provided: {lyric}")
 
 
 
 
 
 
 
 
 
 
68
  if prompt_audio is not None:
69
  print("Using prompt audio for generation")
70
  else:
71
  prompt_audio = op.join(APP_DIR, 'sample/19_2-又是一天过去,烦恼如影随形10s.wav')
72
-
73
- sample_rate = model.cfg.sample_rate
74
 
75
  progress(0.0, "Start Generation")
76
  start = time.time()
@@ -174,6 +187,7 @@ with gr.Blocks(title="LeVo Demo Space") as demo:
174
  )
175
 
176
  # 生成按钮点击事件
 
177
  generate_btn.click(
178
  fn=generate_song,
179
  inputs=[description, lyric, prompt_audio, cfg_coef, temperature, top_k],
 
4
  import numpy as np
5
  from datetime import datetime
6
  import os
7
+ import yaml
8
  import sys
9
  import librosa
10
  import time
 
24
  EXAMPLE_LYRICS = """
25
  [intro-short]
26
 
27
+ [verse]
28
  夜晚的街灯闪烁.
29
  我漫步在熟悉的角落.
30
  回忆像潮水般涌来.
 
33
  那些曾经的甜蜜.
34
  如今只剩我独自回忆.
35
 
36
+ [bridge]
37
  手机屏幕亮起.
38
  是你发来的消息.
39
  简单的几个字.
 
43
  我多想回到从前.
44
  重新拥有你的陪伴.
45
 
46
+ [chorus]
47
  回忆的温度还在.
48
  你却已不在.
49
  我的心被爱填满.
 
56
  [outro-short]
57
  """.strip()
58
 
59
+ with open('conf/vocab.yaml', 'r', encoding='utf-8') as file:
60
+ STRUCTS = yaml.safe_load(file)
61
+
62
 
63
  # 模拟歌曲生成函数
64
  def generate_song(description, lyric, prompt_audio=None, cfg_coef=None, temperature=None, top_k=None, progress=gr.Progress(track_tqdm=True)):
65
  global model
66
  params = {'cfg_coef':cfg_coef, 'temperature':temperature, 'top_k':top_k}
67
  params = {k:v for k,v in params.items() if v is not None}
68
+ sample_rate = model.cfg.sample_rate
69
 
70
  # 生成过程
71
  print(f"Generating song with description: {description}")
72
  print(f"Lyrics provided: {lyric}")
73
+
74
+ # 适配lyric格式
75
+ lyric = lyric.replyricace("\n\n", " ; ")
76
+ for s in STRUCTS:
77
+ lyric = lyric.replyricace(f"{s}\n", f"{s} ")
78
+ lyric = lyric.replyricace("\n", "")
79
+ lyric = lyric.replyricace(". ; ", " ; ")
80
+ print(lyric)
81
+
82
+ # 适配prompt
83
  if prompt_audio is not None:
84
  print("Using prompt audio for generation")
85
  else:
86
  prompt_audio = op.join(APP_DIR, 'sample/19_2-又是一天过去,烦恼如影随形10s.wav')
 
 
87
 
88
  progress(0.0, "Start Generation")
89
  start = time.time()
 
187
  )
188
 
189
  # 生成按钮点击事件
190
+
191
  generate_btn.click(
192
  fn=generate_song,
193
  inputs=[description, lyric, prompt_audio, cfg_coef, temperature, top_k],