Alsa Audio library - Error -> Has no PCM member - python

I'm working on a project where I have to control 8 audio channel.
I'm programming in python3 using alsaaudio library. It all worked but I have these 3 errors and, once I start the program, my internet connection goes down.
In the following code, you can see how I initialize the device (octosound card by AudioInjector). Please note that if the indentitation is wrong is just because a copy paste error.
import alsaaudio
def start_device(ch):
variables.mut.acquire()
if variables.device_flag[ch] == 1:
try:
variables.device_PCM[ch] = alsaaudio.PCM(type=alsaaudio.PCM_PLAYBACK, mode = alsaaudio.PCM_NORMAL,device=variables.device_name[ch])
variables.device_flag[ch] = 0 # device open
print('device -%s- OPEN' % (variables.device_name[ch]))
except:
print("Except raised")
json_builder.jsonerror("Init device ch" + str(ch) +" FAILED to OPEN",ch)
variables.device_flag[ch] == 1
else:
print("Device -%s- already opened" % (variables.device_name[ch]))
variables.mut.release()
The strange things are that this code works and I can drive all 8 channels but I got 3 errors and my internet stop working:
message: "Module 'alsaaudio' has no 'PCM' member"
message: "Module 'alsaaudio' has no 'PCM_PLAYBACK' member"
message: "Module 'alsaaudio' has no 'PCM_NORMAL' member"
(the device=device_name[ch] works, no error)

Well, I will recommend you to use Alvas.Audio Library which can edit, convert, play, pause convert audio files. The C# Alvas.Audio library can also be used to convert headerless format (SLINEAR) etc.
http://alvas.net/alvas.audio,tips.aspx
Moreover it helps to extract AVI streams and convert one file format to another. So, try the Alvas.Audio C# library and get free trial https://www.filerepairtools.com/alavas-audio-library.html

Related

OSError: exception: access violation. Yenista Laser instrument on Python

Looking for other similar errors, we have an issue on loading the DLL library supplied with the Yenista laser instrument.
The DLL is correctly loaded while using the python version indicated in the instrument guide (Python 3.4).
Unfortunately, we need Python 3.10 or at least (>3.8) for other instruments.
We have two different files in our folder: CT400_lib.dll and CT400_lib.h (header file).
It looks like that, using this Python version, the DLL functions cause the following error: OSError: exception: access violation reading 0xFFFFFFFFB6E38700
According to the documentation of ctype, it seems that the DLL is resolved differently in the two Python versions.
We have no idea how to use this DLL with the newer Python version. The instrument is old and the company that produces this instrument does not exists anymore.
Our code:
from ctypes import *
dll_ct400 = cdll.LoadLibrary(r"address")
# (we also tried with "dll_ct400 =WinDLL(r"address"))
class Yenista_Control():
[...]
def initYenista(self):
tcError = create_string_buffer(1024)
strRet = create_string_buffer(1024)
iErrorSize = c_int * 1
(iError) = (iErrorSize())
self.uiHandle = c_longlong(dll_ct400.CT400_Init(byref(iError)))
print("{}{}".format("Error/Warning: ", iError[0]))
if self.uiHandle:
strRet = 'OK'
else: strRet = 'Error: could not connect to CT400'
print(strRet)
return strRet
def YenistaLaserSetting(self):
dll_ct400.CT400_SetLaser(self.uiHandle, self.LI_1, self.ENABLE, 10, self.LS_TunicsT100s_HP,
c_double(1530.0), c_double(1570.0), 100)
if self.uiHandle:
strRet = 'OK'
else: strRet = 'Error: could not connect to CT400'
print(strRet)
return strRet
It seems recognizing the "dll_ct400.CT400_Init" in def initYenista, giving the error when trying to access all other functions, as the YenistaLaserSetting reported above.

can someone tell me why I am getting 'urllib.error.HTTPError: HTTP Error 404: Not Found' in my python pytube script?

So I have this python pytube script to get all the streams of Youtube video
import sys
from pytube import YouTube
url = 'https://www.youtube.com/watch?v=XBkr9k9WmeI'
try:
video = YouTube(url)
except:
print("exception caught")
sys.exit()
streams = video.streams.order_by('itag')
for st in streams:
print(st, end=" ")
but on running this script I get this error urllib.error.HTTPError: HTTP Error 404: Not Found on line streams = video.streams.order_by('itag') where I am trying to get all the streams ordered by itag of video and store it in streams.
The URL is also correct as there is no exception caught in video = Youtube(url) if the url was invalid or something this line would not execute.
And also I have same code in another file in the same project folder but that script works fine and I get no error or anything. The other code is as follows:
def downloadYoutube(url, quality, path):
#exception handling if the video link is valid or not
try:
video = YouTube(url)
except:
print("invalid url")
return
#getting the video title
videoTitle= video.title+'.mp4'
#getting all the atreams of video
allStreams = video.streams.order_by('itag')
#separately saving the progressive streams
progrssiveStreams = allStreams.filter(progressive=True)
# separately saving the non-progressive streams
nonProgrossiveStreams = allStreams.filter(adaptive=True)
# separately saving the mp4 format video streams
mp4Streams = nonProgrossiveStreams.filter(mime_type='video/mp4')
This code runs perfectly. In this code I can filter streams and store it in different variables but the above code give an error. The screenshot of the error is as follows:
can someone help me out on why I am getting this error.
Just upgrade your pytube package and run your code again. The current version is 10.8.5
Go to your terminal and type in
pip install pytube --upgrade

How to play video with python-vlc?

I would like to play video with python-vlc module. I wrote the following code. My computer is MacOS Catalina.
#!/usr/bin/env python3
import vlc
p = vlc.MediaPlayer("mediafile.mp4")
p.play()
while True:
pass
But the python3 interpreter threw the following errors.
[00007f89b9661950] caopengllayer vout display error: No drawable-nsobject found!
[00007f89b9661950] macosx vout display error: No drawable-nsobject nor vout_window_t found, passing over.
[00007f89b30530f0] main video output error: video output creation failed
[00007f89b9650c00] main decoder error: failed to create video output
[h264 # 0x7f89b407c000] get_buffer() failed
[h264 # 0x7f89b407c000] thread_get_buffer() failed
[h264 # 0x7f89b407c000] decode_slice_header error
[h264 # 0x7f89b407c000] no frame!
I guessed that this code didn't make a frame displaying the video. It'll be a main cause of this error, I think.
However, I can not come up with a solution of this problem.
Please tell me how to play video with python-vlc module!!
I think the possible reason is, it requires an active hwnd where it can show the video.
So you need an GUI and set hwnd to that player.
Here is my code for Tkinter Window.You can also check out different GUI based example From Github
import vlc
from tkinter import *
root=Tk()
instance=vlc.Instance()
p=instance.media_player_new()
p.set_hwnd(root.winfo_id())
p.set_media(instance.media_new(path_to_media))
p.play()
root.mainloop()
And if you r using Mac ,then as per the example
you should use instaed of this line
p.set_hwnd(root.winfo_id())
try:
libtk = 'libtk%s.dylib' % (Tk.TkVersion,)
prefix = getattr(sys, 'base_prefix', sys.prefix)
libtk = joined(prefix, 'lib', libtk)
dylib = cdll.LoadLibrary(libtk)
# getNSView = dylib.TkMacOSXDrawableView is the
# proper function to call, but that is non-public
# (in Tk source file macosx/TkMacOSXSubwindows.c)
# and dylib.TkMacOSXGetRootControl happens to call
# dylib.TkMacOSXDrawableView and return the NSView
_GetNSView = dylib.TkMacOSXGetRootControl
# C signature: void *_GetNSView(void *drawable) to get
# the Cocoa/Obj-C NSWindow.contentView attribute, the
# drawable NSView object of the (drawable) NSWindow
_GetNSView.restype = c_void_p
_GetNSView.argtypes = c_void_p,
del dylib
except (NameError, OSError): # image or symbol not found
def _GetNSView(unused):
return None
libtk = "N/A"
h = root.winfo_id() # .winfo_visualid()?
# XXX 1) using the videopanel.winfo_id() handle
# causes the video to play in the entire panel on
# macOS, covering the buttons, sliders, etc.
# XXX 2) .winfo_id() to return NSView on macOS?
v= _GetNSView(h)
if v:
p.set_nsobject(v)
else:
p.set_xwindow(h)# plays audio, no video
I think this will work:
import vlc
media = vlc.MediaPlayer("1.mp4")
media.play()
It just takes a media filename for you.
Make sure the video is in the same folder as the script.

Python error ValueError: Unknown network interface None

import scapy.all as scapy
import requests
import json
This code work with API for getting information about venders
def vender_finding(mac_adr):
mac_url = 'http://macvendors.co/api/%s'
vender = (requests.get(mac_url % mac_adr))
response_dict = json.loads(json.dumps(vender.json()))
return response_dict['result']['company']
This code returns all devices connected to the network. result is something like this
the result of this code
def scan(ip):
arp_request = scapy.ARP(pdst=ip)
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast/arp_request
This is the line which gives an error
answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
clents_list = []
for element in answered_list[1:]:
company = vender_finding(element[1].hwsrc)
clent_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc, "vender": company}
clents_list.append(clent_dict)
print(clents_list)
return clents_list
scan('192.168.1.0/24')
but now its return error like this.
In here now a new error starts to occur.
answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
This the error that I am getting.
raise ValueError("Unknown network interface %r" % name)
ValueError: Unknown network interface None
By installing the following software issue solved.
1.python 2.7.2 from python.org
2.Microsoft Visual C++ Compiler for Python 2.7 from https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266.
(check this link for more. Microsoft Visual C++ 9.0 is required)
3.pip install scapy==2.4.3rc1 (this is recommended by StackOverflow contributor. this work very well.)
(check these link answer for a recommendation by user Cukic0d. GUID number of windows interface giving error: ValueError: Unknown network interface '{1619EEF1-4D71-4831-87AC-8E5DC3AA516A}')
4.winpcap (to perform scapy sniff() must install this)
Install python 2.7.2 and then install Microsoft Visual C++ Compiler for Python 2.7
You can try "iface" with your network interface.
Ex:
sendp(Ether()/IP(dst="1.2.3.4",ttl=(1,4)), iface="eth1")
More info: https://scapy.readthedocs.io/en/latest/usage.html

How to quit VLC after playing a mp3 file

I have this function and I need to close the file before exiting the function say("some text").
def say(self, text):
tts = gTTS(text, lang='fr')
file="text.mp3"
tts.save(file)
audio = MP3(file)
p = vlc.MediaPlayer(file)
p.play()
time.sleep((audio.info.length)) #to avoid it listening to itself
p.stop()
return file
Because If I don't do this, I have this error
OS Error: [Errno -9993] Illegal combination of I/O device
I think that this error occurs because I'm trying to listen just after the call of the function say and the file is still open.
nb: I'm working with Python 3
Though i am not to experienced with TTS, shouldnt it work if you just do close(os.getcwd()+'/'+file)?

Categories

Resources