我试图将Jasper(https://github.com/jasperproject/jasper-client)与houndify python sdk集成。我试图将Houndify整合到Jasper的语音到文本引擎(https://github.com/jasperproject/jasper-client/blob/master/client/stt.py)中。
问题是所有的stt引擎都被定义为抽象类的继承类,我需要为Houdify定义一个继承的类。 transcribe()方法返回transcribbed文本,但Houndify使用类来返回文本。
那么如何在继承类(Houdify stt类)的方法中包含一个类(Houndify转录类),以便类(Houndify转录类)返回的值应该由继承类的方法返回? / p>
要整合的代码:
import wave
import houndify
import sys
import time
# The code below will demonstrate how to use streaming audio through Hound
if __name__ == '__main__':
# We'll accept WAV files but it should be straightforward to
# use samples from a microphone or other source
BUFFER_SIZE = 512
CLIENT_ID =
CLIENT_KEY =
#
# Simplest HoundListener; just print out what we receive.
#
# You can use these callbacks to interact with your UI.
#
class MyListener(houndify.HoundListener):
def onFinalResponse(self, response):
transcribed = response['AllResults']
print "\n"
print transcribed[0]['FormattedTranscription']
def onError(self, err):
print "Error: " + str(err)
client = houndify.StreamingHoundClient(CLIENT_ID, CLIENT_KEY, "test_user")
fname = 'whatistheweatherthere.wav'
audio = wave.open(fname)
client.setSampleRate(audio.getframerate())
samples = audio.readframes(BUFFER_SIZE)
finished = False
client.start(MyListener())
while not finished:
finished = client.fill(samples)
samples = audio.readframes(BUFFER_SIZE)
if len(samples) == 0:
break
client.finish()
代码集成位置: 以上stt.py