Use webengine video and audio codecs - python

For my PyQt5 project, I am using the QWebEngineView, but certain videos, such as .mp4 videos won't play. Can I install the codecs with pip, or pass a certain argument through QApplication() or something similar in order to fix this problem?
I installed PyQt5 through pip, so I don't have the C:\Qt\... files, only the PyQt5, pyqt5_tools folders in Appdata\Local\Programs\Python\Python37\Lib\site-packages.
I am using Python 3.7.2, and PyQt5.11

The pyqtwebengine provided by pypi does not enable the use_proprietary_codecs flag so you cannot play the .mp4.
If you want to get a pyqtwebengine that plays mp4 you must follow these steps:
You must compile Qt with the WEBENGINE_CONFIG += use_proprietary_codecs flag to enable the codecs needed to play mp4(Qt WebEngine Features: Audio and Video Codecs)
Then using that Qt you must compile pyqtwebengine.

Related

Why is the playsound function not able to play my mp3 file in python

So basically I was trying to create a music playing program that would play music when you asked it to. I was just trying to get the song playing portion to actually work, so I wrote a super simple code to test it out:
import playsound
playsound('sample.mp3')
This was done in replit, and I added the mp3 file into the files section
when I hit run, it gives me TypeError: 'module' object is not callable. What can I do to fix this?
you need to install the PyObjC by writing below command.
if you are using python version 3
pip3 install PyObjC
if you are using python version 2
pip install PyObjC
After that you write below code in your terminal
from playsound import playsound
playsound("path of your audio file/testing_audio_file.mp3")
if you are facing any issue regarding path then use below pattern for (use two forward slash) Windows
playsound("D:\\path_of_your_audio_file\\testing_audio_file.mp3")
Replace
import playsound
with...
from playsound import playsound

Adding a sound affect to python code in VSC

I have been trying to add sound to my python code. I tried using playsound, pygame, pydub and tkinter but in vsc it doesn't let me install any using the command pip3 install pygame...(and so on)
here I have tried it with pydub but this sais that there is no module named pydub and it doesn't let me install it. Can someone help me add this sound to my code?
from pydub import AudioSegment
from pydub.playback import play
psong = AudioSegment.from_mp3("song.mp3")
play(song)
I have two suggestions for this issue:
Install pyaudio (pip3 install pyaudio) as this is the best module that pydub uses.
Change your audio file format to wav instead of mp3 and also change this section of code: psong = AudioSegment.from_mp3("song.mp3") to psong = AudioSegment.from_wav("song.wav").
Source for answer

Google Cloud Text-to-Speech Audio to Browser

I use google-cloud text-to-speech API using python3 on linux.
The mp3 plays with os.startfile(), which opens a player.
Instead sending mp3 file & using mp3 player, I need to play audio through the browser.
I have tried:
“Python Media Player” —-defunct.
“20.1. webbrowser”— defunct.
“Rhythmbox” —simply another player.
“Pygame” — overkill.
"Pyglet" - overkill
SoX and pySoX, —Don’t appear to play the files they manipulate.
I read part of Schwoebel’s “An Introduction to Voice Computing in Python.”
"gl_talk" — Wasn't able to implement; very little documentation.
I need advice on how to mimic what google has done in the browser as in the link here:
https://cloud.google.com/text-to-speech
You can use the gTTS module to do text-to-speech in Python. And then you can use another module to play the sound using Python as well.
First install the following modules...
pip install gTTS
pip install playsound
Then you can do this...
from gtts import gTTS
import playsound
tts = gTTS('hello')
tts.save('hello.mp3')
playsound.playsound('hello.mp3')
This code should give you the same results as google in browser, because gtts uses the same API. If you have any problems you can comment and I will definitely reply :)

Python 2.7.14--- importing vlc module on mac OS

in the last couple of days I was developing an APP on python IDLE.
I tried to import the vlc module, when I run it I get this error:
OSError: dlopen(libvlccore.dylib, 6): image not found
I installed the module with this command: pip install python-vlc.
I hope you can help me getting it work!
Thanks in advance!
Zaid Zaim
python-vlc is just Python bindings for libVLC.
Without that library, it won't do you any good, because all it does is try to load that library (a .dylib, .so, or .dll, depending on your platform) and call functions out of it.
There should be installation instructions at the wiki page linked above, but on a Mac, the easiest way is to just install the VLC player. I know that if you install it with Homebrew, you get the library, in a location that python-vlc can find. But I think even the binary installer from the front page of the main VideoLAN website will work as well.
If you're using Homebrew, you'll want to read the docs for when to search brew vs. brew cask vs. other taps,1 or search somewhere like Mac App Store for the current status. But at present, the appropriate command appears to be:
brew cask install vlc
1. Generally, anything that you'd expect to find as a double-clickable app in /Applications, as opposed to a Unix command-line tool or a support library, is going to be a cask, and therefore in the tap cask, which has special shortcuts to access it. But that's a relatively new thing, and not every recipe has been converted yet.
brew install --cask vlc
Is the latest command, and it works for me!

Using Pygame without installing

I'm making a real simple RPG game at college and I would like to use pygame. However, my college has a group policy disabling any Windows executables from running so I can't install pygame. Is there any way I can just import pygame by just having it in the same folder?
One thing I do with external python libraries is to download the source, build it and copy the built library into ${PROJECT_HOME}/lib/${EXTERNAL_LIB_NAME}. This way, I can run my python scripts with just standard python installation on a machine. To be able to use the external lib, you'll have to include the lib directory to sys path like this:
import os
from sys import path as syspath
syspath.append(os.path.join(os.path.dirname(__file__), 'lib'))
P.S.: Since pygame has C/C++ files to be compiled, you'd have to use mingw instead. Refer to this answer for that: error: Unable to find vcvarsall.bat
EDIT: In case you're wondering how to build pygame from source, you'll need to run setup.py build. This will build the python library into 'build' folder of the package directory and there you'd see how it should be placed in Python's directory. You will face the compilation problem in Windows as I've mentioned before, but you can easily fix that.
EDIT 2: Download link to contents of 'lib' for PyGame:
Python 2.7: http://dl.dropbox.com/u/71422266/pygame27.7z
Python 3.2: http://dl.dropbox.com/u/71422266/pygame32.7z
If you're allowed to run stuff from a USB drive, one option would be to use Portable Python 2.7.3.2, which includes PyGame 1.9.1.

Categories

Resources