Guest User

Untitled

a guest
Nov 26th, 2024
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. import torch
  2. import time
  3. import outetts
  4.  
  5. device = torch.device("cuda:0")
  6.  
  7. # Configure the GGUF model
  8. model_config = outetts.GGUFModelConfig_v1(
  9.     model_path="OuteTTS-0.2-500M-Q6_K.gguf",
  10.     language="en",  # Supported languages in v0.2: en, zh, ja, ko
  11.     n_gpu_layers=24,
  12.     device=device    
  13. )
  14.  
  15. interface = outetts.InterfaceGGUF(model_version="0.2", cfg=model_config)  # Initialize the GGUF interface
  16. speaker = interface.load_default_speaker(name="male_1")  # Load a default speaker profile
  17.  
  18. def calculate_audio_duration(output):
  19.     audio_tensor = output.audio
  20.     sample_rate = output.sr
  21.     num_samples = audio_tensor.size(1)
  22.    
  23.     print(f"Samples: {num_samples}")
  24.     print(f"Sample Rate: {sample_rate}")
  25.    
  26.     return num_samples / sample_rate
  27.  
  28. # Function to perform inference and time it
  29. def synthesize(text):
  30.     start_time = time.time()  # Record start time
  31.     output = interface.generate(
  32.         text=text,
  33.         temperature=0.1,
  34.         repetition_penalty=1.1,
  35.         max_length=4096,
  36.         speaker=speaker,
  37.     )
  38.     end_time = time.time()  # Record end time
  39.    
  40.     inference_time = end_time - start_time  # Calculate duration
  41.     audio_duration = calculate_audio_duration(output)
  42.     print(f"Inference time for '{text}': {audio_duration:.4f} seconds audio in {inference_time:.4f} seconds")
  43.     return output
  44.  
  45. # Text to synthesize
  46. text_to_synthesize_1 = "Speech synthesis is the artificial production of human speech. A computer system used for this purpose is called a speech synthesizer, and it can be implemented in software or hardware products."
  47. text_to_synthesize_2 = "Hello my boy"
  48.  
  49. # Perform synthesis and timing for both texts
  50. synthesize(text_to_synthesize_1).save("output1.wav")
  51.  
Advertisement
Add Comment
Please, Sign In to add comment