【问题标题】:how to implement Speech To Text using python houndify?如何使用 python houndify 实现 Speech To Text?
【发布时间】:2017-02-27 13:56:29
【问题描述】:

我是 houndify 的新手,我一直在创建 STT(语音转文本)流程。我有一个想法来使用 python 创建它。我选择了 houndify python 2.7 SDK。我已经获得了 houndify 服务的客户端 ID 和客户端密钥.那么我该如何进行语音到文本的转换?请逐步解决它?

【问题讨论】:

    标签: python-2.7 speech-to-text houndify


    【解决方案1】:

    Python SDK 包含两个示例脚本,它们展示了如何向 Houndify 发送语音查询:sample_stdin.py 和 sample_wave.py。无论音频来源如何,步骤如下:

    1. 使用 clientID、clientKey 和一些用户 ID 初始化 houndify.StreamingHoundClient 对象(在开发期间可以是“test_user”,但理想情况下应该对应于您的最终用户)
    2. 扩展houndify.HoundListener
    3. 将监听器的实例传递给 StreamingHoundClient 对象的 start() 方法
    4. 循环读取音频块(8/16 kHz 单声道 16 位 little-endian PCM 样本)并将其输入客户端:client.fill(samples)
    5. 流式传输完成后调用client.finish()

    您可以在此处找到有关 SDK 的更多详细信息(包括有关设置请求信息字段的信息): https://docs.houndify.com/sdks/docs/python.

    这是一个简单的脚本,它从标准输入读取音频并仅打印部分脚本、最终响应或错误消息:

    import sys
    import houndify
    
    
    class MyListener(houndify.HoundListener):
    
      def onPartialTranscript(self, transcript):
        print "Partial transcript: " + transcript
    
      def onFinalResponse(self, response):
        print "Final response: " + str(response)
    
      def onError(self, err):
        print "Error: " + str(err)
    
    
    client = houndify.StreamingHoundClient(<CLIENT_ID>, <CLIENT_KEY>, "test_user", sampleRate = 8000)
    
    BUFFER_SIZE = 512
    
    client.start(MyListener())
    
    while True:
      samples = sys.stdin.read(BUFFER_SIZE)
      if len(samples) == 0: break
    
      finished = client.fill(samples)
      if finished: break
    
    client.finish()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-11
      • 2019-07-09
      • 2019-06-28
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      相关资源
      最近更新 更多