current position:Home>Python utility module playsound

Python utility module playsound

2022-01-31 12:16:45 Notes of the lost schoolboy

This is my participation 11 The fourth of the yuegengwen challenge 12 God , Check out the activity details :2021 One last more challenge

Environmental Science

  • windows 10 64 position
  • anaconda with python 3.8
  • playsound 1.3.0

Preface

above Python Text voice broadcast Introduced the use of Library pyttsx3 To realize voice broadcasting .pyttsx3 It's a string , That is the text , This article introduces another library playsound, It broadcasts content from voice files , such as mp3 file .playsound Support for multiple platforms , Only depend on python.

install

The official installation method is

pip install playsound
 Copy code 

But when I was executing , I found the wrong report , Prompt to download the corresponding source package

playsound

Then download it , Unzip after completion , I installed... Here git Tools for , All can be used directly git shell To operate the , It simulates linux Environment , You can use it directly tar Command to decompress

playsound

then , Let's switch to the target python A virtual environment , Enter the source directory , Use command

pip install .
 Copy code 

Installation

playsound

Use

After installed , It's very simple to use

from playsound import playsound
playsound('play.mp3')
 Copy code 

playsound Method also has an optional parameter block, It's a boolean type , The default is True, If it is False, Represents asynchronous execution

principle

Because the underlying audio playing mechanism of each platform is different ,playsound It is also the method of calling the respective platform itself , No new mechanism has been introduced

  • windows

    It uses windll.winmm, The formats that have passed the test include wav and mp3

  • macos

    It uses AppKit.NSSound, The formats that have passed the test include wav and mp3, In general ,QuickTime Can broadcast ,playsound Can also broadcast

  • linux

    It uses GStreamer, because linux There are too many distributions , The author also said that there was no complete test , If you have questions, you can submit issue or pr

Python Practical module topic

More useful python modular , Please move

xugaoxiang.com/category/py…

Reference material

copyright notice
author[Notes of the lost schoolboy],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201311216426135.html

Random recommended