回答編集履歴

1

edit

2018/01/11 15:01

投稿

mkgrei
mkgrei

スコア8560

test CHANGED
@@ -3,3 +3,87 @@
3
3
 
4
4
 
5
5
  音声に反応しないことですが、pythonからではなく直接実行すると正しい応答があるという仮定のもとで考えてよろしいのでしょうか?
6
+
7
+
8
+
9
+ ---
10
+
11
+
12
+
13
+ 追記
14
+
15
+ エラーを再現しました。
16
+
17
+ Juliusが走りだす前にソケットを開いてしまうせいみたいです。
18
+
19
+ 少し待ってあげると動きます。
20
+
21
+
22
+
23
+ ```python
24
+
25
+ # coding:utf-8
26
+
27
+ import subprocess
28
+
29
+ import socket
30
+
31
+ import time
32
+
33
+
34
+
35
+ def main():
36
+
37
+ p = subprocess.Popen("./run-dnn-mod.sh", stdout=subprocess.PIPE, shell=True)
38
+
39
+ print('Initiating')
40
+
41
+ time.sleep(5)
42
+
43
+ print('Done')
44
+
45
+ pid = str(p.pid)
46
+
47
+
48
+
49
+ host = 'localhost'
50
+
51
+ port = 10500
52
+
53
+
54
+
55
+ client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
56
+
57
+ client.connect((host, port))
58
+
59
+
60
+
61
+ while True:
62
+
63
+ try:
64
+
65
+ data = client.recv(1024).decode("utf-8")
66
+
67
+ if len(data) > 1:
68
+
69
+ print(data)
70
+
71
+ except KeyboardInterrupt:
72
+
73
+ print ("KeyboardInterrupt occured.")
74
+
75
+ p.kill()
76
+
77
+ subprocess.call("kill " + pid, shell=True)
78
+
79
+ client.close()
80
+
81
+ quit()
82
+
83
+
84
+
85
+ if __name__ == "__main__":
86
+
87
+ main()
88
+
89
+ ```