diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-09-15 18:45:38 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-09-25 20:28:59 +0200 |
| commit | 8d2e10462a79fc34c446d837cb9af6a5d5171efd (patch) | |
| tree | f4a52c0388f5fd30e605e46d22b99d210160c0e9 /client/stt.py | |
| parent | 36a98507a56630a94fc111ba943b149ec1938a94 (diff) | |
| download | jasper-client-8d2e10462a79fc34c446d837cb9af6a5d5171efd.tar.gz jasper-client-8d2e10462a79fc34c446d837cb9af6a5d5171efd.zip | |
Read Framerate from wave file in GoogleSTT
Diffstat (limited to 'client/stt.py')
| -rw-r--r-- | client/stt.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/client/stt.py b/client/stt.py index 4a46e71..cf32a74 100644 --- a/client/stt.py +++ b/client/stt.py @@ -2,6 +2,7 @@ # -*- coding: utf-8-*- import os import traceback +import wave import json import tempfile import logging @@ -177,7 +178,6 @@ Excerpt from sample profile.yml: class GoogleSTT(AbstractSTTEngine): SLUG = 'google' - RATE = 16000 def __init__(self, api_key=None): #FIXME: get init args from config """ @@ -211,13 +211,17 @@ class GoogleSTT(AbstractSTTEngine): audio_file_path -- the path to the .wav file to be transcribed """ + wav = wave.open(fp, 'rb') + frame_rate = wav.getframerate() + wav.close() + 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") data = fp.read() try: - headers = {'Content-type': 'audio/l16; rate=%s' % GoogleSTT.RATE} + headers = {'Content-type': 'audio/l16; rate=%s' % frame_rate} response = self.http.post(url, data=data, headers=headers) response.encoding = 'utf-8' response_read = response.text |
