You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用speech_recognition+whisper语音识别遇双环境报错,求解决

OGG转WAV后使用Whisper语音识别的环境报错问题

我是编程新手,这是我的首次提问。我编写了一段程序,需先将.ogg音频文件转换为.wav格式,再进行语音识别。代码如下:

import speech_recognition
import pydub


def ogg2wav(filename):
    new_filename = filename.replace('.ogg', '.wav')
    audio = pydub.AudioSegment.from_file(filename)
    audio.export(new_filename, format='wav')
    return new_filename


ogg2wav("audio.ogg")

recognizer = speech_recognition.Recognizer()
with speech_recognition.WavFile('audio.wav') as source:
    wav_audio = recognizer.record(source)
print(recognizer.recognize_whisper(wav_audio, language='ru'))

Windows 7 + Python 3.8 环境报错

运行时出现如下错误:

Traceback (most recent call last):
  File "C:/Users/Алексей/PycharmProjects/pythonProject1/skillbox_voice_transform.py", line 17, in <module>
    print(recognizer.recognize_whisper(wav_audio, language='ru'))
  File "C:\Users\Алексей\AppData\Roaming\Python\Python38\site-packages\speech_recognition\__init__.py", line 1408, in recognize_whisper
    import whisper
  File "C:\Users\Алексей\AppData\Roaming\Python\Python38\site-packages\whisper.py", line 69, in <module>
    libc = ctypes.CDLL(libc_name)
  File "C:\Program Files\Python38\lib\ctypes\__init__.py", line 363, in __init__
    if '/' in name or '\\' in name:
TypeError: argument of type 'NoneType' is not iterable

我在谷歌上搜索过该错误,但仅找到通用信息。

已安装模块列表

aiohttp==3.8.4
aiosignal==1.3.1
async-timeout==4.0.2
attrs==23.1.0
certifi==2023.5.7
cffi==1.16.0
charset-normalizer==3.1.0
colorama==0.4.6
ffmpeg-downloader==0.3.0
ffmpeg-python==0.2.0
ffprobe==0.5
filelock==3.14.0
frozenlist==1.3.3
fsspec==2024.3.1
future==1.0.0
idna==3.4
intel-openmp==2021.4.0
Jinja2==3.1.4
MarkupSafe==2.1.5
mkl==2021.4.0
mpmath==1.3.0
multidict==6.0.4
networkx==3.1
numpy==1.24.4
openai==0.27.7
packaging==24.0
platformdirs==4.2.1
pycparser==2.22
pydub==0.25.1
pyTelegramBotAPI==4.17.0
requests==2.31.0
six==1.16.0
soundfile==0.12.1
SpeechRecognition==3.10.4
sympy==1.12
tbb==2021.12.0
telebot==0.0.5
torch==2.2.1
tqdm==4.65.0
typing_extensions==4.11.0
urllib3==2.0.2
vk==3.0
vk-api==11.9.9
whisper==1.1.10
yarl==1.9.2

Windows 10 + Python 3.12 环境报错

尝试在该环境运行代码,出现如下错误:

Traceback (most recent call last):
  File "C:\Users\root\Downloads\pythonProject1\skillbox_voice_transform.py", line 17, in <module>
    print(recognizer.recognize_whisper(wav_audio, language='ru'))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\speech_recognition\__init__.py", line 1407, in recognize_whisper
    import torch
  File "C:\Users\root\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\torch\__init__.py", line 141, in <module>
    raise err
OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\root\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\torch\lib\shm.dll" or one of its dependencies.

我确实执行了pip install torch命令,请问这种情况是什么问题?感谢各位的解答。


内容的提问来源于stack exchange,提问作者Alex Nedelchuk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 21:58:13