터미널에서 수행
pip install pyttsx3 #Text to Speach 엔진 다운로드
pip install gtts #Google Text to Speech API를 사용할 수 있는 라이브러리 다운로드
pip install playsound #Python 소리 다운로드
Q. 파이썬을 이용해서 한글 텍스트를 한글 음성으로 변환하는 코드를 작성해줘. API가 아닌 무료로 사용할 수 있는 라이브러리를 사용해줘
from gtts import gTTS
import os
def text_to_speech(text, output_file):
tts = gTTS(text, lang='ko')
tts.save(output_file)
os.system(output_file) # 음성 파일 실행
if __name__ == "__main__":
input_text = "안녕하세요. 반갑습니다."
output_file = "output.mp3"
text_to_speech(input_text, output_file)