简体   繁体   English

python 没有名为 playsound 的模块

[英]python no module named playsound

Trying to get some speechrecognition going here on a raspberry pi running raspbian os but no matter what I do im getting the error "no module named playsound".试图在运行 raspbian 操作系统的树莓派上进行一些语音识别,但无论我做什么,我都会收到错误“没有名为 playsound 的模块”。 I'm using pip install playsound and getting successful install.我正在使用 pip 安装 playsound 并成功安装。 Im using pip freeze |我正在使用 pip 冻结 | grep play and getting playsound ==1.2.2. grep 播放并获得播放声音 ==1.2.2。 I have loaded up the latest Raspbian os but same results.我已经加载了最新的 Raspbian 操作系统,但结果相同。 the playsound files are where the should be.播放声音文件在应该在的地方。 I have tried pip3 install.我试过 pip3 安装。 I have tried uninstall of both and reinstall on just pip. I have upgraded pip and raspbian.我已经尝试卸载两者并仅在 pip 上重新安装。我已经升级了 pip 和 raspbian。 the code is the default nothing special.代码是默认的没什么特别的。 Out of ideas and any help would be appreciated here.出于想法和任何帮助,我们将不胜感激。

import os
import time
import playsound
import speech_recognition as sr
from gtts import gTTS

def speak(text):
   tts = gTTS(text=text, lang="en-uk")
   filename = "voice.mp3"
   tts.save(filename)
   playsound.playsound(filename)

speak("hello")

If you run your python program with python3 {python_file}.py , try to use如果您使用python3 {python_file}.py运行 python 程序,请尝试使用

python3 -m pip install

Or if you run your python program with python {python_file}.py , use或者,如果您使用python {python_file}.py运行 python 程序,请使用

python -m pip install

This will guarantee that the pip is referring to the exact python version you are using.这将保证 pip 指的是您正在使用的确切 python 版本。

After mucking about for quite some time I never got playsound working but had no issues with pydub.在折腾了很长一段时间后,我从来没有让 playsound 工作,但 pydub 没有问题。 With pydub it just worked as intended.使用 pydub 它只是按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM