From 78f0b5b8344dad427902b84210dc4d217c9d9205 Mon Sep 17 00:00:00 2001 From: schneefux Date: Mon, 15 Sep 2014 15:20:25 +0200 Subject: Use with statement to open file in Google STT engine --- client/stt.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/stt.py b/client/stt.py index a83b6c7..1960a4b 100644 --- a/client/stt.py +++ b/client/stt.py @@ -186,9 +186,8 @@ class GoogleSTT(AbstractSTTEngine): url = "https://www.google.com/speech-api/v2/recognize?output=json&client=chromium&key=%s&lang=%s&maxresults=6&pfilter=2" % ( self.api_key, "en-us") - wav = open(audio_file_path, 'rb') - data = wav.read() - wav.close() + with open(audio_file_path, 'rb') as f: + data = f.read() try: headers = {'Content-type': 'audio/l16; rate=%s' % GoogleSTT.RATE} -- cgit v1.3.1