zoukankan      html  css  js  c++  java
  • python语音识别2

    识别器类

    SpeechRecognition 的核心就是识别器类。

    Recognizer API 主要目是识别语音,每个 API 都有多种设置和功能来识别音频源的语音,分别是:

    recognize_bing(): Microsoft Bing Speech
    recognize_google(): Google Web Speech API
    recognize_google_cloud(): Google Cloud Speech - requires installation of the google-cloud-speech package
    recognize_houndify(): Houndify by SoundHound
    recognize_ibm(): IBM Speech to Text
    recognize_sphinx(): CMU Sphinx - requires installing PocketSphinx
    recognize_wit(): Wit.ai
    

      

    以上七个中只有 recognition_sphinx()可与CMU Sphinx 引擎脱机工作, 其他六个都需要连接互联网。

    SpeechRecognition 附带 Google Web Speech API 的默认 API 密钥,可直接使用它。其他六个 API 都需要使用 API 密钥或用户名/密码组合进行身份验证,因此本文使用了 Web Speech API。

    现在开始着手实践,在解释器会话中调用 recognise_google()函数。

     r.recognize_google()
    

      

    相信你已经猜到了结果,怎么可能从空文件中识别出数据呢?

    这 7 个 recognize_*()  识别器类都需要输入 audio_data 参数,且每种识别器的 audio_data 都必须是 SpeechRecognition 的 AudioData 类的实例。

    AudioData 实例的创建有两种路径:音频文件或由麦克风录制的音频,先从比较容易上手的音频文件开始。

    音频文件的使用
    首先需要下载音频文件(https://github.com/realpython/python-speech-recognition/tree/master/audio_files),保存到 Python 解释器会话所在的目录中。
    
    AudioFile 类可以通过音频文件的路径进行初始化,并提供用于读取和处理文件内容的上下文管理器界面。
    

      

    支持文件类型

    SpeechRecognition 目前支持的文件类型有:

    WAV: 必须是 PCM/LPCM 格式

    AIFF

    AIFF-C

    FLAC: 必须是初始 FLAC 格式;OGG-FLAC 格式不可用

    若是使用 Linux 系统下的 x-86 ,macOS 或者是 Windows 系统,需要支持 FLAC文件。若在其它系统下运行,需要安装 FLAC 编码器并确保可以访问 flac 命令。

  • 相关阅读:
    Linux下安装SVN服务端小白教程
    在 Linux 下搭建 Git 服务器
    Linux系统中安装软件的几种方式
    springboot系列(十)springboot整合shiro实现登录认证
    shiro系列五、shiro密码MD5加密
    springboot系列(九)springboot使用druid数据源
    springboot系列(七) 项目热加载
    访问网页出现DNS错误
    SpringBoot入门
    MyBatisCodeHelper-Pro插件破解版[2.8.2] 【拒绝度盘】
  • 原文地址:https://www.cnblogs.com/huaobin/p/15677071.html
Copyright © 2011-2022 走看看