poemsforaphrodite commited on
Commit
09274b3
1 Parent(s): a65bab4

Upload openvoice_app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. openvoice_app.py +28 -1
openvoice_app.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import torch
3
  import argparse
4
  import gradio as gr
 
5
  import langid
6
  from openvoice import se_extractor
7
  from openvoice.api import BaseSpeakerTTS, ToneColorConverter
@@ -20,8 +21,22 @@ device = 'cuda' if torch.cuda.is_available() else 'cpu'
20
  output_dir = 'outputs'
21
  os.makedirs(output_dir, exist_ok=True)
22
 
23
-
24
  supported_languages = ['zh', 'en']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def predict(prompt, style, audio_file_pth):
27
  text_hint = ''
@@ -43,6 +58,18 @@ def predict(prompt, style, audio_file_pth):
43
  save(audio, f'{output_dir}/output.wav')
44
 
45
  save_path = f'{output_dir}/output.wav'
 
 
 
 
 
 
 
 
 
 
 
 
46
  return text_hint, save_path, audio_file_pth
47
 
48
  # Gradio interface setup
 
2
  import torch
3
  import argparse
4
  import gradio as gr
5
+ import requests
6
  import langid
7
  from openvoice import se_extractor
8
  from openvoice.api import BaseSpeakerTTS, ToneColorConverter
 
21
  output_dir = 'outputs'
22
  os.makedirs(output_dir, exist_ok=True)
23
 
24
+ api_key = os.environ.get("ELEVENLABS_API_KEY")
25
  supported_languages = ['zh', 'en']
26
+ # Function to get all voices
27
+ def get_voices(api_key):
28
+ url = "https://api.elevenlabs.io/v1/voices"
29
+ headers = {"xi-api-key": api_key}
30
+ response = requests.request("GET", url, headers=headers)
31
+ return response.json()
32
+
33
+ # Function to delete a voice by ID
34
+ def delete_voice(api_key, voice_id):
35
+ url = f"https://api.elevenlabs.io/v1/voices/{voice_id}"
36
+ headers = {"xi-api-key": api_key}
37
+ response = requests.request("DELETE", url, headers=headers)
38
+ return response.status_code, response.text
39
+
40
 
41
  def predict(prompt, style, audio_file_pth):
42
  text_hint = ''
 
58
  save(audio, f'{output_dir}/output.wav')
59
 
60
  save_path = f'{output_dir}/output.wav'
61
+ data = get_voices(api_key)
62
+ # Find all voice IDs with the name "TrialVoice"
63
+ trial_voice_ids = [voice.get("voice_id") for voice in data['voices'] if voice.get("name") == "TrialVoice"]
64
+
65
+ # Delete each voice with the name "TrialVoice"
66
+ for voice_id in trial_voice_ids:
67
+ status_code, response_text = delete_voice(api_key, voice_id)
68
+ print(f"Deleted voice ID {voice_id}: Status Code {status_code}, Response {response_text}")
69
+
70
+ if not trial_voice_ids:
71
+ print("No voices with the name 'TrialVoice' found.")
72
+
73
  return text_hint, save_path, audio_file_pth
74
 
75
  # Gradio interface setup