Skip to content

Instantly share code, notes, and snippets.

@ikegami-yukino
Created November 18, 2017 07:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikegami-yukino/a22d57f2b2935264da4a17f8e840cc96 to your computer and use it in GitHub Desktop.
Save ikegami-yukino/a22d57f2b2935264da4a17f8e840cc96 to your computer and use it in GitHub Desktop.
Python script of Julius on Windows
# 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