Getting audio from a URL and playing it - python

There is a link to an mp3 file that needs to be streamed from a URL like http://example.com/music_radio.mp3 and played on a computer. On the Internet, although there are examples of streaming audio, but they are mainly for Python2, and for Python3 there are no such libraries anymore, I tried to do it this way:
import vlc
p = vlc.MediaPlayer ("http://example.com/music_radio.mp3")
p.play ()
But it constantly displays an error:
Traceback (most recent call last): File "PythonProjects / URL /
main.py", line 2, in import vlc File "PythonProjects / URL / venv /
lib / python3.6 / site-packages / vlc / init.py", line 3, in public
import ModuleNotFoundError: No module named 'public'
And the problem is that the public module is not installed. How can you solve this problem or how else can you receive and play audio by reference?
UPD: That link suggests either non-working code, or code using Python2, not Python3
UPD2: When using python-vlc, this error occurs:
Traceback (most recent call last): File
"PythonProjects/URL/main.py", line 4, in
import vlc File "PythonProjects/URL/venv/lib/python3.6/site-packages/vlc.py",
line 203, in
dll, plugin_path = find_lib() File "PythonProjects/URL/venv/lib/python3.6/site-packages/vlc.py",
line 194, in find_lib
ctypes.CDLL('libvlccore.dylib') File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ctypes/init.py",
line 348, in init
self._handle = _dlopen(self._name, mode) OSError: dlopen(libvlccore.dylib, 6): image not found

If this can help
from IPython.display import Audio
Audio(url="http://www.nch.com.au/acm/8k16bitpcm.wav")

Related

Why do I keep getting an error when I try to download only the audio of a Youtube video using pytube?

I am trying to download the audio of a video using pytube, but I keep getting an error that I don't understand.
My code is:
from pytube import YouTube
lista_de_videos = ["https://www.youtube.com/watch?v=iYYRH4apXDo"]
for video in lista_de_videos:
yt = YouTube(video)
yt.streams.get_audio_only().download('/Users/applemacosx/Downloads')
The error that I keep getting is:
/Users/applemacosx/PycharmProjects/pythonProject6/venv/bin/python /Users/applemacosx/PycharmProjects/pythonProject6/download.py
Traceback (most recent call last):
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/extract.py", line 288, in apply_descrambler
stream_data[key] = [
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/extract.py", line 290, in <listcomp>
"url": format_item["url"],
KeyError: 'url'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/applemacosx/PycharmProjects/pythonProject6/download.py", line 84, in <module>
yt = YouTube(video)
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/__main__.py", line 92, in __init__
self.descramble()
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/__main__.py", line 132, in descramble
apply_descrambler(self.player_config_args, fmt)
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/extract.py", line 300, in apply_descrambler
cipher_url = [
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/extract.py", line 301, in <listcomp>
parse_qs(formats[i]["cipher"]) for i, data in enumerate(formats)
KeyError: 'cipher'
Process finished with exit code 1
Can someone explain to me what I am doing wrong, please?
the keyerror:'cipher'issue was fixed on the pytube repository a long time ago. You just need to reinstall pytube from the repository link
pip uninstall pytube
pip install git+https://github.com/nficano/pytube
Try it this way:
from pytube import YouTube
yt=YouTube(link)
t=yt.streams.filter(only_audio=True).all()
t[0].download(/path)
Reference:- Download audio from YouTube using pytube
First thing you have to do is:
pip3 uninstall pytube
`pip3 install pytube3`
You can try pytubex as well
After looking all over for this. This is the only thread I found which has solutions. This problem seems to be because of two files in the pytube3 folder, namely, extract.py and ciphers.py. You need to change some code in them. Visit
https://github.com/nficano/pytube/issues/641

pyinstaller, poppler, and other dependencies

I am a new developer, and probably well beyond my scope right now. I have made a script that uses several dependencies I had to install on my personal PC, and I cannot install them on my work PC. I know the code itself works as intended when I use it at home with all dependencies available. This is where I get beyond my scope as I do not know how to include these dependencies with my distribution version. I have used pyinstaller to attempt to "catch" the dependencies when compiling to a .exe, but to no avail.
Here is a snippet of my dependencies
import pytesseract
import sys
import tkinter as tk
import os
from PIL import Image
from tkinter import Button
from pdf2image import convert_from_path
from tkinter import filedialog
from tkinter import messagebox
from PIL import ImageTk as itk
poppler_path = r"D:\7-10\Receiver Reader V0.1\poppler\bin"
pytesseract.pytesseract.tesseract_cmd = r'D:\7-10\Receiver Reader V0.1\Tesseract-OCR\tesseract'
Here is the error I get on the work PC
Exception in Tkinter callback
Traceback (most recent call last):
File "site-packages\pdf2image\pdf2image.py", line 409, in pdfinfo_from_path
File "subprocess.py", line 854, in __init__
File "subprocess.py", line 1307, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tkinter\__init__.py", line 1883, in __call__
File "ReceiverReaderV1.py", line 69, in run_reader_prog
File "site-packages\pdf2image\pdf2image.py", line 89, in convert_from_path
File "site-packages\pdf2image\pdf2image.py", line 430, in pdfinfo_from_path
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
Any help is greatly appreciated,
Thank you!

Getting error message when attempting to use python-magic to identify file types on windows

I am new to Python with some knowledge of C++. I am getting the following error message when trying to set up python-magic to identify file types. I have already installed python-magic and libmagic using pip. As soon as I try to import magic I get the error message prompting me to check my installation.
Error message:
# python
>>> import magic
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import magic
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\magic.py", line 173, in <module>
raise ImportError('failed to find libmagic. Check your installation')
ImportError: failed to find libmagic. Check your installation
>>>
Thanks guys, now I am able to import magic, but I am getting another error message when I try to type magic.from_file("userinput.py") after placing the magic1.dll and libgnurx-0.dll files into my
C:\Windows\System32 folder. Error message follows:
# python
>>> import magic
>>> magic.from_file("userinput.py")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
magic.from_file("userinput.py")
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\magic.py", line 130, in from_file
m = _get_magic_type(mime)
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\magic.py", line 118, in _get_magic_type
i = _instances[mime] = Magic(mime=mime)
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\magic.py", line 67, in __init__
magic_load(self.cookie, magic_file)
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\magic.py", line 256, in magic_load
return _magic_load(cookie, coerce_filename(filename))
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\magic.py", line 187, in errorcheck_negative_one
raise MagicException(err)
magic.MagicException
>>>
I think the problem is I am having trouble passing the location of magic.mgc using the following pseudo command: file_magic = magic.Magic(magic_file="c:path\to\magic.mgc")
Any further help would be greatly appreciated. Thank you all.
It sounds like you don't have the proper dependencies set up. Have you followed the installation instructions from the github page?
"On Windows, copy magic1.dll, regex2.dll, and zlib1.dll onto your PATH from the Binaries and Dependencies zipfiles provided by the File for Windows project. You will need to copy the file magic out of [binary-zip]\share\misc, and pass it's location to Magic(magic_file=...). If you are using a 64-bit build of python, you'll need 64-bit libmagic binaries which can be found here: https://github.com/pidydx/libmagicwin64 (note: untested)"
From https://github.com/ahupp/python-magic#dependencies:
Dependencies
On Windows, copy magic1.dll, regex2.dll, and zlib1.dll onto your PATH from the Binaries and Dependencies zipfiles provided by the File for Windows project. You will need to copy the file magic out of [binary-zip]\share\misc, and pass it's location to Magic(magic_file=...). If you are using a 64-bit build of python, you'll need 64-bit libmagic binaries which can be found here: https://github.com/pidydx/libmagicwin64 (note: untested)

Google cloud sdk not working when python points python3

I am currently trying to install google cloud sdk on my macbook. I am using scikit-learn and anaconda for machine learning so on my laptop python points to python3.5. However google cloud sdk requires python 2.7 for installation, and that's why I am facing the problem of not be able to install it.
when I ran the install.sh file the error occurred and I have no clue how to deal with it:
Adam | ~ $ git/google-cloud-sdk/install.sh
Welcome to the Google Cloud SDK!
Traceback (most recent call last):
File "/Users/AdamLiu/Git/google-cloud-sdk/lib/third_party/enum/__init__.py", line 364, in __getattr__
return cls._member_map_[name]
KeyError: '_convert'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/AdamLiu/git/google-cloud-sdk/bin/bootstrapping/install.py", line 8, in <module>
import bootstrapping
File "/Users/AdamLiu/Git/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 9, in <module>
import setup
File "/Users/AdamLiu/Git/google-cloud-sdk/bin/bootstrapping/setup.py", line 34, in <module>
from googlecloudsdk.core.util import platforms
File "/Users/AdamLiu/Git/google-cloud-sdk/lib/googlecloudsdk/core/util/platforms.py", line 18, in <module>
import platform
File "/Users/AdamLiu/anaconda/lib/python3.5/platform.py", line 117, in <module>
import sys, os, re, subprocess
File "/Users/AdamLiu/anaconda/lib/python3.5/subprocess.py", line 364, in <module>
import signal
File "/Users/AdamLiu/anaconda/lib/python3.5/signal.py", line 8, in <module>
_IntEnum._convert(
File "/Users/AdamLiu/Git/google-cloud-sdk/lib/third_party/enum/__init__.py", line 366, in __getattr__
raise AttributeError(name)
AttributeError: _convert
Super thanks in advance!
Set the CLOUDSDK_PYTHON environment variable to the location of your Python 2.x executable before running install.sh.
Or make sure that you have python2 in your path so that which python2 can find it.

Python Error "WindowsError: [Error 127] The specified procedure could not be found"

I'm running a python script importing dataextract (from tableau api) csv,os, and datetime
when I run it I'm getting this error and I don't know where to start looking.The only line of code I am running is
import dataextract as tde
And I installed this library following tableau's tutorial
http://www.tableausoftware.com/learn/tutorials/on-demand/extract-api-introduction?signin=f850b055b106d24b93b365faad64838f
Traceback (most recent call last):
File "C:/Users/Ofri Harlev/Documents/Python/TableauFlatScript.py", line 1, in <module>
import dataextract as tde
File "C:\Python27\lib\site-packages\dataextract\__init__.py", line 15, in <module>
from Base import *
File "C:\Python27\lib\site-packages\dataextract\Base.py", line 17, in <module>
from . import StringUtils
File "C:\Python27\lib\site-packages\dataextract\StringUtils.py", line 17, in <module>
tablib = libs.load_lib
File "C:\Python27\lib\site-packages\dataextract\Libs.py", line 35, in load_lib
self.lib = ctypes.cdll.LoadLibrary(self.lib_path)
File "C:\Python27\lib\ctypes\__init__.py", line 443, in LoadLibrary
return self._dlltype(name)
File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 127] The specified procedure could not be found
After trying everything I found that the Tableau Extract Library only works on computers were Tableau is installed
I have faced the same problem while working with Python 2.7 and this is what I found:
-- Problem was coming because I have installed multiple versions of python (Python3.2, Python3.5 etc).
-- Because of multiple versions, at runtime there was multiple DLLs with same name (in all python versions library). So it was unable to figure out which one to load.
Solution:
I have uninstalled all python versions except one I needed (Python2.7) at time. Then run the program and now everything was working fine for me.

Categories

Resources