Emmylahot12 commited on
Commit
ba1b2e2
·
verified ·
1 Parent(s): 2d95c7e

Update Infer.py

Browse files
Files changed (1) hide show
  1. Infer.py +12 -15
Infer.py CHANGED
@@ -1,21 +1,18 @@
1
  import tensorflow as tf
 
2
  import numpy as np
3
  import soundfile as sf
4
- import os
5
 
6
- MODEL_PATH = "model/clone_tts_model.h5"
7
- TEXT_MAX_LEN = 100
8
- SAMPLE_RATE = 22050
9
 
10
- def generate_speech(text_input):
11
- x_input = np.array([[ord(c) for c in text_input.ljust(TEXT_MAX_LEN)[:TEXT_MAX_LEN]]])
12
- model = tf.keras.models.load_model(MODEL_PATH)
13
- audio = model.predict(x_input)[0]
14
- os.makedirs("output", exist_ok=True)
15
- output_path = "output/generated.wav"
16
- sf.write(output_path, audio, SAMPLE_RATE)
17
- print(f"Generated speech saved at: {output_path}")
18
 
19
- if __name__ == "__main__":
20
- text = input("Enter text to synthesize: ")
21
- generate_speech(text)
 
 
 
 
 
1
  import tensorflow as tf
2
+ import librosa
3
  import numpy as np
4
  import soundfile as sf
 
5
 
6
+ # Load the trained model
7
+ model = tf.keras.models.load_model('model/clone_tts_model.h5')
 
8
 
9
+ # Define input text
10
+ text_input = "Hello, welcome to CloneTTS. This is an example of text-to-speech synthesis."
 
 
 
 
 
 
11
 
12
+ # Generate the speech (preprocess as needed depending on model requirements)
13
+ speech = model.predict(np.array([text_input]))
14
+
15
+ # Save the generated speech to a .wav file
16
+ sf.write('output/speech.wav', speech, 22050) # Adjust sample rate as necessary
17
+
18
+ print("Speech generated and saved as 'output/speech.wav'")