NeuralFalcon commited on
Commit
aee70db
·
verified ·
1 Parent(s): de85bf8

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +9 -8
api.py CHANGED
@@ -5,22 +5,25 @@ import os
5
  from gradio_client import Client
6
 
7
  # Ensure the output directory exists
8
- output_dir = "temp_audio"
9
  os.makedirs(output_dir, exist_ok=True)
10
 
11
  # Initialize the Gradio client
12
  api_url = "http://127.0.0.1:7860/"
13
  client = Client(api_url)
14
 
 
 
 
15
  def text_to_speech(
16
  text="Hello!!",
17
  model_name="kokoro-v0_19.pth",
18
  voice_name="af_bella",
19
  speed=1,
20
- trim=0,
21
  pad_between_segments=0,
22
  remove_silence=False,
23
  minimum_silence=0.05,
 
24
  ):
25
  """
26
  Generates speech from text using a specified model and saves the audio file.
@@ -30,10 +33,10 @@ def text_to_speech(
30
  model_name (str): The name of the model to use for synthesis.
31
  voice_name (str): The name of the voice to use.
32
  speed (float): The speed of speech.
33
- trim (int): Whether to trim silence at the beginning and end.
34
  pad_between_segments (int): Padding between audio segments.
35
  remove_silence (bool): Whether to remove silence from the audio.
36
  minimum_silence (float): Minimum silence duration to consider.
 
37
  Returns:
38
  str: Path to the saved audio file.
39
  """
@@ -43,13 +46,12 @@ def text_to_speech(
43
  model_name=model_name,
44
  voice_name=voice_name,
45
  speed=speed,
46
- trim=trim,
47
  pad_between_segments=pad_between_segments,
48
  remove_silence=remove_silence,
49
  minimum_silence=minimum_silence,
 
50
  api_name="/text_to_speech"
51
  )
52
-
53
  # Save the audio file in the specified directory
54
  save_at = f"{output_dir}/{os.path.basename(result)}"
55
  shutil.move(result, save_at)
@@ -63,14 +65,13 @@ if __name__ == "__main__":
63
  model_name="kokoro-v0_19.pth" #kokoro-v0_19-half.pth
64
  voice_name="af_bella" #get voice names
65
  speed=1
66
- only_trim_both_ends_silence=0
67
  add_silence_between_segments=0 #it use in large text
68
  remove_silence=False
69
  keep_silence_upto=0.05 #in seconds
 
70
  audio_path = text_to_speech(text=text, model_name=model_name,
71
  voice_name=voice_name, speed=speed,
72
- trim=only_trim_both_ends_silence,
73
  pad_between_segments=add_silence_between_segments,
74
  remove_silence=remove_silence,
75
  minimum_silence=keep_silence_upto)
76
- print(f"Audio file saved at: {audio_path}")
 
5
  from gradio_client import Client
6
 
7
  # Ensure the output directory exists
8
+ output_dir = "api_output"
9
  os.makedirs(output_dir, exist_ok=True)
10
 
11
  # Initialize the Gradio client
12
  api_url = "http://127.0.0.1:7860/"
13
  client = Client(api_url)
14
 
15
+
16
+
17
+
18
  def text_to_speech(
19
  text="Hello!!",
20
  model_name="kokoro-v0_19.pth",
21
  voice_name="af_bella",
22
  speed=1,
 
23
  pad_between_segments=0,
24
  remove_silence=False,
25
  minimum_silence=0.05,
26
+ custom_voicepack=None,
27
  ):
28
  """
29
  Generates speech from text using a specified model and saves the audio file.
 
33
  model_name (str): The name of the model to use for synthesis.
34
  voice_name (str): The name of the voice to use.
35
  speed (float): The speed of speech.
 
36
  pad_between_segments (int): Padding between audio segments.
37
  remove_silence (bool): Whether to remove silence from the audio.
38
  minimum_silence (float): Minimum silence duration to consider.
39
+ custom_voicepack (str): Path to the custom voice pack to use.
40
  Returns:
41
  str: Path to the saved audio file.
42
  """
 
46
  model_name=model_name,
47
  voice_name=voice_name,
48
  speed=speed,
 
49
  pad_between_segments=pad_between_segments,
50
  remove_silence=remove_silence,
51
  minimum_silence=minimum_silence,
52
+ custom_voicepack=custom_voicepack,
53
  api_name="/text_to_speech"
54
  )
 
55
  # Save the audio file in the specified directory
56
  save_at = f"{output_dir}/{os.path.basename(result)}"
57
  shutil.move(result, save_at)
 
65
  model_name="kokoro-v0_19.pth" #kokoro-v0_19-half.pth
66
  voice_name="af_bella" #get voice names
67
  speed=1
 
68
  add_silence_between_segments=0 #it use in large text
69
  remove_silence=False
70
  keep_silence_upto=0.05 #in seconds
71
+ custom_voicepack=None
72
  audio_path = text_to_speech(text=text, model_name=model_name,
73
  voice_name=voice_name, speed=speed,
 
74
  pad_between_segments=add_silence_between_segments,
75
  remove_silence=remove_silence,
76
  minimum_silence=keep_silence_upto)
77
+ print(f"Audio file saved at: {audio_path}")