kanahomaisa commited on
Commit
fda4a12
·
verified ·
1 Parent(s): 6f0c174

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -17,31 +17,29 @@ sys.path.append(f'{ROOT_DIR}/third_party/Matcha-TTS')
17
  from cosyvoice.cli.cosyvoice import CosyVoice
18
  from cosyvoice.utils.file_utils import load_wav
19
 
20
- def download_audio_from_drive(file_id, save_path="temp_prompt.wav"):
21
- url = f"https://drive.google.com/uc?export=download&id={file_id}"
22
- response = requests.get(url)
23
- if not response.ok or b"<html" in response.content[:100]:
24
- raise RuntimeError("Google Drive 音檔下載失敗")
25
- with open(save_path, "wb") as f:
26
- f.write(response.content)
27
- return save_path
28
-
29
  preset_speakers = {
30
  "6歲": {
31
- "file_id": "1PomN05sTjxXBR3q5kOgB7CUEpig2HJmx",
32
  "transcription": "名字是微笑號,只是呢你們看,這一輛微笑號它這裡有寫八百型的喔,它是八百山出來"
33
  },
34
  "8歲": {
35
- "file_id": "1U1DKzN_BsU-DL02HZIRlx-opUJLhaQ41",
36
  "transcription": "出來了出來了,你知道這個餐具是可以挖的,這個餐具可以用窩課魅一起挖嗎?"
37
  }
38
  }
39
 
 
 
 
 
 
 
 
40
  def apply_preset(speaker_key):
41
- if speaker_key and speaker_key in preset_speakers:
42
- file_id = preset_speakers[speaker_key]["file_id"]
43
  transcription = preset_speakers[speaker_key]["transcription"]
44
- local_path = download_audio_from_drive(file_id)
45
  return local_path, transcription
46
  return None, ""
47
 
 
17
  from cosyvoice.cli.cosyvoice import CosyVoice
18
  from cosyvoice.utils.file_utils import load_wav
19
 
 
 
 
 
 
 
 
 
 
20
  preset_speakers = {
21
  "6歲": {
22
+ "url": "https://huggingface.co/datasets/kanahomaisa/breezyvoice-samples/resolve/main/smile_train.wav",
23
  "transcription": "名字是微笑號,只是呢你們看,這一輛微笑號它這裡有寫八百型的喔,它是八百山出來"
24
  },
25
  "8歲": {
26
+ "url": "https://huggingface.co/datasets/kanahomaisa/breezyvoice-samples/resolve/main/utensils.wav",
27
  "transcription": "出來了出來了,你知道這個餐具是可以挖的,這個餐具可以用窩課魅一起挖嗎?"
28
  }
29
  }
30
 
31
+ def download_audio_from_hf(url, save_path="temp_prompt.wav"):
32
+ response = requests.get(url)
33
+ response.raise_for_status()
34
+ with open(save_path, "wb") as f:
35
+ f.write(response.content)
36
+ return save_path
37
+
38
  def apply_preset(speaker_key):
39
+ if speaker_key in preset_speakers:
40
+ url = preset_speakers[speaker_key]["url"]
41
  transcription = preset_speakers[speaker_key]["transcription"]
42
+ local_path = download_audio_from_hf(url)
43
  return local_path, transcription
44
  return None, ""
45