【问题标题】:Changing Language in Python SpeechRecognition在 Python SpeechRecognition 中更改语言
【发布时间】:2018-07-25 11:24:16
【问题描述】:

我在我的 Python 应用程序中使用 SpeechRecognition。但是,它只能识别英语。我希望它也能识别其他语言。我知道这是可能的。任何人都可以帮助我改变Python2.7中语音识别语言的语法吗 请帮忙!提前致谢。到目前为止,这是我的代码:

import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
    try:
        audio = r.listen(source)
        text = r.recognize_google(audio)
    except:
        pass

【问题讨论】:

    标签: python python-2.7 speech-recognition google-speech-api


    【解决方案1】:

    语言可以作为参数传递给识别谷歌函数

    r.recognize_google(audio, language="hi-IN")
    

    可以在这个 StackOverflow 答案http://stackoverflow.com/a/14302134中找到支持的语言标签列表

    【讨论】:

      【解决方案2】:

      因此,您需要在请求中的配置中发送语言代码

      client = speech.SpeechClient()
      audio = types.RecognitionAudio(uri=url)
      
      config = types.RecognitionConfig(
              encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
              language_code='es-US'   // Language code Español (Estados Unidos)
          )
      response = client.long_running_recognize(config, audio)
      

      有关可用语言模型的更多详细信息please refer here

      【讨论】:

      • 我得到这个错误但是...... AttributeError: 'module' object has no attribute 'SpeechClient'
      • 你是如何导入模块的?
      • 您的代码用于谷歌云语音到文本 api。而我使用的是 Pypi 上可用的 Speech_recognition,它使用谷歌网络语音。链接在这里:pypi.org/project/SpeechRecognition
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多