最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - can not recognize speech from audio file with Speech framework - Stack Overflow

programmeradmin0浏览0评论

I've been using PyObjC for recognizing text from audio file applying Speech framework. So I check documentation and create this small script, but he was returning an error. What's my error?

import Speech


def record():
    recognize_request = Speech.SFSpeechRecognizer()
    if not recognize_request.isAvailable():
        raise NotImplementedError
    nsurl = Speech.NSURL.fileURLWithPath_(u"/Users/aleksandr/PycharmProjects/flask/file.wav")

    request = Speech.SFSpeechURLRecognitionRequest.alloc().initWithURL_(nsurl)
    function = lambda func, err: func.bestTranscription.formattedString()
    out = recognize_request.recognitionTaskWithRequest_resultHandler_(request, function)
    return function(out, None)


print(record())

Error:

AttributeError: '_SFSpeechRecognitionBlockTask' object has no attribute 'bestTranscription'

I expect a a string with recognized text.

发布评论

评论列表(0)

  1. 暂无评论