我正在尝试将 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() 方法返回转录的文本,但 Houndify 使用一个类来返回文本。
那么如何在继承类(Houdify stt 类)的方法中包含一个类(Houndify 转录类),以便类(Houndify 转录类)返回的值应该由继承类的方法返回?
要集成的代码:
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