03. 텍스트를 음성으로 변환

진나희·2023년 8월 20일
0

python_with_chatgpt

목록 보기
3/5
post-thumbnail

터미널에서 수행

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)
ModuleNotFoundError: No module named 'gtts'
일경우 대화형으로 코드 실행하면 된다,, 이유가 뭘까,,
profile
안녕하세요! data와 chatgpt에 관심이 많습니다.

0개의 댓글