Created
November 18, 2017 07:37
-
-
Save ikegami-yukino/a22d57f2b2935264da4a17f8e840cc96 to your computer and use it in GitHub Desktop.
Python script of Julius on Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
import re | |
import socket | |
import subprocess | |
import time | |
HOST = "127.0.0.1" | |
PORT = 10500 | |
JULIUS_DIR = 'C:\Program Files (x86)\julius-4.4.2-win32bin\\' | |
re_word = re.compile('WORD="([^"]+)"') | |
def main(): | |
p = subprocess.Popen([JULIUS_DIR + "julius.exe", "-C", JULIUS_DIR + "main.jconf", "-dnnconf", JULIUS_DIR + "main.dnnconf", "-module", ">", "nul"], | |
stdout=subprocess.PIPE, shell=True) | |
time.sleep(4) | |
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
client.connect((HOST, PORT)) | |
print('SPEECH START') | |
try: | |
data = "" | |
while 1: | |
if "</RECOGOUT>" in data: | |
words = '' | |
for word in filter(bool, re_word.findall(data)): | |
words += word | |
if words: | |
print(words) | |
data = "" | |
else: | |
data = data + client.recv(1024) | |
except KeyboardInterrupt: | |
print("KeyboardInterrupt occured.") | |
p.kill() | |
client.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment