Browse Source

orc, tts python

tobby48 4 years ago
parent
commit
223e663f42

BIN
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/data/quiz.jpg View File


BIN
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/data/test1.PNG View File


BIN
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/data/test2.PNG View File


+ 3
- 0
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/s1_image_to_text.py View File

@@ -0,0 +1,3 @@
1
+import pytesseract
2
+pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract'
3
+print(pytesseract.image_to_string('data\\test1.PNG',lang='kor'))

+ 5
- 0
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/s2_text_to_voice.py View File

@@ -0,0 +1,5 @@
1
+from gtts import gTTS
2
+text ="안녕하세요"
3
+
4
+tts = gTTS(text=text, lang='ko')
5
+tts.save("data\\hello.mp3")

+ 19
- 0
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/s3_mp3_play.py View File

@@ -0,0 +1,19 @@
1
+import pygame
2
+
3
+music_file = "data\\hello.mp3"   # mp3 or mid file
4
+
5
+
6
+freq = 16000    # sampling rate, 44100(CD), 16000(Naver TTS), 24000(google TTS)
7
+bitsize = -16   # signed 16 bit. support 8,-8,16,-16
8
+channels = 1    # 1 is mono, 2 is stereo
9
+buffer = 2048   # number of samples (experiment to get right sound)
10
+
11
+# default : pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
12
+pygame.mixer.init(freq, bitsize, channels, buffer)
13
+pygame.mixer.music.load(music_file)
14
+pygame.mixer.music.play()
15
+
16
+clock = pygame.time.Clock()
17
+while pygame.mixer.music.get_busy():
18
+    clock.tick(30)
19
+pygame.mixer.quit() 

+ 28
- 0
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/s4_image_to_text_to_voice.py View File

@@ -0,0 +1,28 @@
1
+from gtts import gTTS
2
+import pygame
3
+import pytesseract
4
+
5
+pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract'
6
+text = pytesseract.image_to_string('data\\test2.PNG',lang='kor')
7
+print(text)
8
+tts = gTTS(text=text, lang='ko')
9
+tts.save("data\\hello.mp3")
10
+
11
+
12
+music_file = "data\\hello.mp3"   # mp3 or mid file
13
+
14
+
15
+freq = 16000    # sampling rate, 44100(CD), 16000(Naver TTS), 24000(google TTS)
16
+bitsize = -16   # signed 16 bit. support 8,-8,16,-16
17
+channels = 1    # 1 is mono, 2 is stereo
18
+buffer = 2048   # number of samples (experiment to get right sound)
19
+
20
+# default : pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
21
+pygame.mixer.init(freq, bitsize, channels, buffer)
22
+pygame.mixer.music.load(music_file)
23
+pygame.mixer.music.play()
24
+
25
+clock = pygame.time.Clock()
26
+while pygame.mixer.music.get_busy():
27
+    clock.tick(30)
28
+pygame.mixer.quit()