-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpeechStylis.py
37 lines (25 loc) · 1 KB
/
SpeechStylis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
"""text-to-voice.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1Xdzm-Cu1ofbyFv0xp7An-BNiXYYpTchV
"""
!pip install TTS
import torch
from TTS.api import TTS
# Get device
device = "cuda" if torch.cuda.is_available() else "cpu"
# Initialize TTS
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
# Input text
text = "hi guys this is hayden finally i have created text to voice program using machine learning and artificial inteligence"
# Specify the path to the speaker's waveform
speaker_wav_path = "/content/drive/MyDrive/audio.wav"
# Specify the language
language = "en"
# Run TTS
wav = tts.tts(text=text, speaker_wav=speaker_wav_path, language=language)
# Save the waveform to an audio file
output_file_path = "output.wav"
tts.tts_to_file(text=text, speaker_wav=speaker_wav_path, language=language, file_path=output_file_path)
print(f"Text-to-speech completed. Audio saved to: {output_file_path}")