小编Luc*_*ool的帖子

OSX - #include "portaudio.h" 1 生成错误。错误:命令“/usr/bin/clang”失败,退出状态为 1

我正忙于制作语音识别代码,我有这个:

from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *

import os
import pyaudio
import wave
import audioop
from collections import deque
import time
import math

 class SpeechDetector:
     def __init__(self):
        self.CHUNK = 1024
        self.FORMAT = pyaudio.paInt16
        self.CHANNELS = 1
        self.RATE = 16000

        self.SILENCE_LIMIT = 1
        self.PREV_AUDIO = 0.5

        self.THRESHOLD = 4500
        self.num_phrases = -1

        MODELDIR = "../../tools/pocketsphinx/model"
        DATADIR = "../../tools/pocketsphinx/test/data"

        config = Decoder.default_config()
        config.set_string('-hmm', os.path.join(MODELDIR, 'en-us/en-us'))
        config.set_string('-lm', os.path.join(MODELDIR, 'en-us/en-us.lm.bin'))
        config.set_string('-dict', os.path.join(MODELDIR, 'en-us/cmudict-en-us.dict'))

        self.decoder = Decoder(config)

    def setup_mic(self, num_samples=50):
        print "Getting intensity …
Run Code Online (Sandbox Code Playgroud)

python macos terminal pyaudio

1
推荐指数
1
解决办法
1356
查看次数

当说Python时如何开始录制?

我正在尝试制作一个使用语音识别的程序。现在,我遇到了一个问题,那就是您必须按下按钮或Enter才能启动语音识别。您是否可以说出一个短语(类似于Hey Google)来开始识别Python 3中的语音?
这是我的代码:

录制音频代码:

r = sr.Recognizer()

with sr.Microphone() as source:
    audio = r.listen(source)
x = r.recognize_google(audio)

print("I'm listening!")

try:
    print("You said: " + r.recognize_google(audio))
except speech_recognition.UnknownValueError:
    print("I am sorry but I couldn't understand you, try again.")
except speech_recognition.RequestError as e:
    print("Could not request results from Google Speech Recognition service; {0}".format(e))
Run Code Online (Sandbox Code Playgroud)

提前致谢!

python speech python-3.x

1
推荐指数
1
解决办法
847
查看次数

标签 统计

python ×2

macos ×1

pyaudio ×1

python-3.x ×1

speech ×1

terminal ×1