티스토리 뷰

SWDesk

[Python] TTS(text to sound) Example

tothebeyond 2022. 10. 3. 12:46

텍스트를 WAV 파일로 저장

 

text = "R1을 지난 전류는 R3를 지난 전류에 의해 증폭된다.."
from gtts import gTTS
import pydub

fileName = "./tr002.wav"
output = gTTS(text = text, lang='ko')
output.save(fileName)
'''
sound1 = pydub.AudioSegment.from_wav(fileName)
sound1.export("./tr001.mp3",format='mp3')
'''

tr002.wav
0.02MB

from gtts import gTTS

fileName = "E:/Temp/InterviewScenario.txt"
file1 = open(fileName, 'rt', encoding='UTF8')
text1 = ""
while True:
    line1 = file1.readline()
    if not line1: break;
    text1 += line1

file1.close()
tts1 = gTTS(text=text1, lang='ko')
tts1.save("InterviewScenario.mp3")
반응형

'SWDesk' 카테고리의 다른 글

[Python] Compare 'Dict'  (0) 2022.10.11
[Python] DataFrame과 dict 합치기  (0) 2022.10.10
[Python] 클래스 변수 테스트(7)  (0) 2022.09.01
[Python] 클래스 변수 테스트(6)  (0) 2022.08.31
[Python] 클래스 변수 테스트(5)  (0) 2022.08.30
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/03   »
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
글 보관함