日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python语音识别播放音乐_使用python语音识别播放和流式转录音频

發布時間:2025/3/20 python 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python语音识别播放音乐_使用python语音识别播放和流式转录音频 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我是Python的新手,正在嘗試如何在后臺播放聲音的情況下,從文件中實時轉錄音頻語音。在

更新:@petezurich Sorry for the bad question. Currently, I can hear the

audio playing in the background. However, I am having trouble getting

Sphinx to transcribe the audio. Is there something wrong with the way

I am passing the audio to Sphinx?

It's constantly outputting "Sphinx error" message.

我正在使用PocketSpinx和Uberi/語音識別庫。在

到目前為止,我總結了一下:

#!/usr/bin/env python

# recognitions.py : Transcribe Test from an Audio File

import os

import sys

import time

import wave

import pyaudio

import speech_recognition as sr

import threading

try:

import pocketsphinx

except:

print("PocketSphinx is not installed.")

# import audio file within script folder

from os import path

audio_file = path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "samples/OSR_us_000_0061_8k.wav")

print("Transcribing... " + audio_file)

wf = wave.open(audio_file, 'rb')

# set PyAudio instance

pa = pyaudio.PyAudio()

# set recognizer instance (unmodified)

r = sr.Recognizer()

stream_buffer = bytes()

stream_counter = 0

audio_sampling_rate = 48000

def main_recognize(stream):

global audio_sampling_rate

# Create a new AudioData instance, which represents "mono" audio data

audio_data = sr.AudioData(stream, audio_sampling_rate, 2)

# recognize using CMU Sphinx (en-US only)

try:

print("Sphinx: " + r.recognize_sphinx(audio_data, language="en-US"))

except sr.UnknownValueError:

print("Sphinx error")

except sr.RequestError as e:

print("Sphinx error; {0}".format(e))

def stream_audio(data):

global stream_buffer

global stream_counter

buffer_set_size = 200

if stream_counter < buffer_set_size:

# force 'data' to BYTES to allow concat

data = bytes()

stream_buffer += data

stream_counter += 1

else:

threading.Thread(target=main_recognize, args=(stream_buffer,)).start()

# reset

stream_buffer = bytes()

stream_counter = 0

# define callback

def callback(in_data, frame_count, time_info, status):

data = wf.readframes(frame_count)

stream_audio(in_data)

return (data, pyaudio.paContinue)

# open audio stream

stream = pa.open(format=pa.get_format_from_width(wf.getsampwidth()),

channels=wf.getnchannels(),

rate=wf.getframerate(),

output=True,

stream_callback=callback)

# start the stream

stream.start_stream()

# wait for stream to finish

while stream.is_active():

time.sleep(0.1)

# stop stream

stream.stop_stream()

stream.close()

wf.close()

# close PyAudio

pa.terminate()

總結

以上是生活随笔為你收集整理的python语音识别播放音乐_使用python语音识别播放和流式转录音频的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。