summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-09-11 14:48:07 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2014-09-11 14:48:07 +0200
commitc4b9f6b302c3192bc0bd8b9b35978e8c958a1e83 (patch)
treeb2d8d3a92ec433401bd65aa601b9b78c3877e002
parentfa926e876485dfe81b288ac3ee8025c2c7f59895 (diff)
downloadjasper-client-c4b9f6b302c3192bc0bd8b9b35978e8c958a1e83.tar.gz
jasper-client-c4b9f6b302c3192bc0bd8b9b35978e8c958a1e83.zip
Use tempfile in client.g2p
-rw-r--r--client/g2p.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/client/g2p.py b/client/g2p.py
index d22445a..057757e 100644
--- a/client/g2p.py
+++ b/client/g2p.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8-*-
import os
+import tempfile
import subprocess
import re
-TEMP_FILENAME = "g2ptemp"
PHONE_MATCH = re.compile(r'<s> (.*) </s>')
PHONETISAURUS_PATH = os.environ['JASPER_HOME'] + "/phonetisaurus"
@@ -25,12 +25,12 @@ def translateWord(word):
def translateWords(words):
full_text = '\n'.join(words)
- f = open(TEMP_FILENAME, "wb")
- f.write(full_text)
- f.flush()
+ with tempfile.NamedTemporaryFile(suffix='.g2p', delete=False) as f:
+ temp_filename = f.name
+ f.write(full_text)
- output = translateFile(TEMP_FILENAME)
- os.remove(TEMP_FILENAME)
+ output = translateFile(temp_filename)
+ os.remove(temp_filename)
return output