@magrup244
now i've lowered the case in file name however only one single filename is brought up. i mean but, i m sure there many other files shoul be pop up. how can ii solve it?
You are not logged in. Please login or register.
AudioGames.net Forum → Developers room → Pyglet help
@magrup244
now i've lowered the case in file name however only one single filename is brought up. i mean but, i m sure there many other files shoul be pop up. how can ii solve it?
Well, the best way to be sure is to test it under manageable conditions you control. Fill a folder with a small number of files you know the names of, some with matching names, some with different capitalization, and see if the script detects them as expected. If it doesn't, then something is afoot which we can more effectively troubleshoot.
@25
Maybe use os.path.splitext(filename) first, so you don't need to index away the extension all the time.
@28
Good suggestion:
import os.path
import glob
types = [".mp3", ".wav", ".flac", ".mp4", ".mpg", ".avi", ".m4a"]
types = str(types)
path = input("Enter the path to your music folder.")
letter = input("Name of the song? ")
print(os.getcwd())
#list directories
with os.scandir(path) as it:
for entry in it:
if not entry.name.startswith('.') and entry.is_file():
name = os.path.splitext(str(os.path.split(entry)[1]))
if letter in name[0].lower():
if name[1].lower() in types:
print(name[0]+name[1])
@magurp244
i'Ve tested this out with measurable conditions and seems to work better. now i can get tracks in queue with pyglet.media.queue however the tracks probabely would be playing orderly. there for i think a way where users can choos the media file they want to play.
So should i process the "name" as a list to do it?
You could, yes. You may want to match it with the full filename for loading reference, but that way people could select whatever tracks they like. You could also shuffle that name list to load tracks randomly as well, such as:
import random
box = [1,2,3,4,5]
box = random.shuffle(box)
qmagurp244
So i guess need to match filename within using list comperisons right?
Actually, just storing the full filename would probably work. So something like:
import os.path
import glob
types = [".mp3", ".wav", ".flac", ".mp4", ".mpg", ".avi", ".m4a"]
types = str(types)
playlist = []
path = input("Enter the path to your music folder.")
letter = input("Name of the song? ")
print(os.getcwd())
#list directories
with os.scandir(path) as it:
for entry in it:
if not entry.name.startswith('.') and entry.is_file():
name = os.path.splitext(str(os.path.split(entry)[1]))
if letter in name[0].lower():
if name[1].lower() in types:
playlist += [name[0]+name[1]]
You could split the text again when displaying it if you don't want to list the extension, or shuffle the list to randomize playback.
@33
i have joined it like this, something went wrong.
import os.path
import glob
import pyglet
from pyglet.window import key
types = [".mp3", ".wav", ".flac", ".mp4", ".mpg", ".avi", ".m4a"]
types = str(types)
playlist = []
path = input("Enter the path to your music folder.")
letter = input("Name of the song? ")
print(os.getcwd())
#list directories
with os.scandir(path) as it:
for entry in it:
if not entry.name.startswith('.') and entry.is_file():
name = os.path.splitext(str(os.path.split(entry)[1]))
if letter in name[0].lower():
if name[1].lower() in types:
playlist += [name[0]+name[1]]
class Prototype(pyglet.window.Window):
def __init__(self):
super(Prototype, self).__init__(640, 480, resizable=False, fullscreen=False, caption="Test")
self.clear()
self.music = pyglet.media.StaticSource(pyglet.media.load('name[0]',streaming=False))
self.player = pyglet.media.Player()
pyglet.clock.schedule_interval(self.update, .01)
def update(self,dt):
if self.player.playing == False:
self.player.queue(self.music)
self.player.play()
#draw screen
self.draw()
def draw(self):
self.clear()
def on_key_press(self,symbol,modifiers):
if symbol == key.UP and self.player.volume < 2.0:
self.player.volume += 0.1
print(self.player.volume)
if symbol == key.DOWN and self.player.volume > 0.0:
self.player.volume -= 0.1
print(self.player.volume)
if symbol == key.LEFT:
print(self.player.time)
if self.player.time - 10.0 < 0.0:
self.player.seek(0.0)
else:
self.player.seek(self.player.time - 10.0)
print(self.player.time)
if symbol == key.RIGHT:
print(self.player.time)
get_duration = self.music.duration
if self.player.time + 10.0 > get_duration:
self.player.seek(get_duration)
else:
self.player.seek(self.player.time + 10.0)
print(self.player.time)
if symbol == key.ESCAPE:
self.close()
if __name__ == '__main__':
window = Prototype()
pyglet.app.run()
Hm, not the most elegant way of integrating the code, but it seems the issue is when you try loading the sound file in the Prototype class:
self.music = pyglet.media.StaticSource(pyglet.media.load('name[0]',streaming=False))
First, when loading "name[0]" your not including the file extension or the path, so something like:
self.music = pyglet.media.StaticSource(pyglet.media.load(path+"\\"+name[0]+name[1],streaming=False))
Another way would be to just go straight from the playlist though, like so:
self.music = pyglet.media.StaticSource(pyglet.media.load(path+"\\"+playlist[0],streaming=False))
Integrating it with the Prototype class could help with additional searches, changing songs, etc.
@35
the problem here is actually, i can get the output via searching but choosing from output resutls is the matter. You see search existed in the code above. so sould i pick from the entry.name's indexes being able to choose from one of the songs from results?
I merged the file search segment with the prototype class, so what you do is enter the directory and nearest search word, and it will spit out a list of matching songs numbered from first to last. Enter the corresponding number and press enter to play your track of choice:
import os.path
import glob
import pyglet
from pyglet.window import key
class Prototype(pyglet.window.Window):
def __init__(self):
super(Prototype, self).__init__(640, 480, resizable=False, fullscreen=False, caption="Test")
self.clear()
self.types = [".mp3", ".wav", ".flac", ".mp4", ".mpg", ".avi", ".m4a"]
self.types = str(self.types)
self.playlist = []
self.path = input("Enter the path to your music folder.")
self.letter = input("Name of the song? ")
print(os.getcwd())
#list directories
with os.scandir(self.path) as it:
for entry in it:
if not entry.name.startswith('.') and entry.is_file():
name = os.path.splitext(str(os.path.split(entry)[1]))
if self.letter in name[0].lower():
if name[1].lower() in self.types:
self.playlist += [name[0]+name[1]]
## print(self.playlist)
if len(self.playlist) > 0:
for a in range(0,len(self.playlist),1):
print(a,". "+self.playlist[a])
self.index = int(input("select track:"))
self.music = pyglet.media.StaticSource(pyglet.media.load(self.path+"\\"+self.playlist[self.index],streaming=False))
self.player = pyglet.media.Player()
pyglet.clock.schedule_interval(self.update, .01)
def update(self,dt):
if self.player.playing == False:
self.player.queue(self.music)
self.player.play()
#draw screen
self.draw()
def draw(self):
self.clear()
def on_key_press(self,symbol,modifiers):
if symbol == key.UP and self.player.volume < 2.0:
self.player.volume += 0.1
print(self.player.volume)
if symbol == key.DOWN and self.player.volume > 0.0:
self.player.volume -= 0.1
print(self.player.volume)
if symbol == key.LEFT:
print(self.player.time)
if self.player.time - 10.0 < 0.0:
self.player.seek(0.0)
else:
self.player.seek(self.player.time - 10.0)
print(self.player.time)
if symbol == key.RIGHT:
print(self.player.time)
get_duration = self.music.duration
if self.player.time + 10.0 > get_duration:
self.player.seek(get_duration)
else:
self.player.seek(self.player.time + 10.0)
print(self.player.time)
if symbol == key.ESCAPE:
self.close()
if __name__ == '__main__':
window = Prototype()
pyglet.app.run()
Text strings are a bit funny, if you use only a single backslash it interprets the line and the quote marks encapsulating it as a character symbol instead of an actual backslash text string. So putting two backslashes avoids that mischaracterisation.
What would You suggest me to build an equolizer guys? i took a look Pyo seems too complicated. i didn't see enough examples regarding audio equolizer building as well. there are some examples regarding audio spectrum parametres. not sure if that is the right thing to do.
Zignal seems rather interesting, maybe something like SciPy could also work for signal processing. I haven't played around with equalizers much though, so its hard to say. Having said that though, OpenAL Soft does have an equalizer EFX option you can use, and you can find bindings for that in my OpenAL PyLite wrapper. Lets see here, something like this:
from openal import *
import time
class Example(object):
def __init__(self):
#load EFX listener
self.listener = Listener()
#initialize sound
self.sound = LoadSound('LQ_Snare Rev.wav')
#load EFX sound player
self.player = Player()
#create an EFX slot for effects
self.slot = EFXslot()
#create a reverb effect
self.effect1 = equalizer()
#mount the effect into the EFX slot
self.slot.set_effect(self.effect1)
#set listener position
self.listener.position = (320,240,0)
#set player position
self.player.position = (160,240,0)
#load sound into player
self.player.add(self.sound)
#set rolloff factor
self.player.rolloff = 0.01
#move sound from left to right
for a in range(0,15,1):
if a == 5:
#connect a source to output through the EFX slot to apply the effect
self.player.add_effect(self.slot)
self.player.play()
time.sleep(1)
#stop player
self.player.stop()
#clean up resources
self.effect1.delete()
self.player.delete()
self.slot.delete()
self.sound.delete()
self.listener.delete()
Example()
When i'Ve launched the app, interface shows the clasical windows message: 'Program does not respond, either wait or end it'. Since the bug looks untraceable no way i understand whats wrong with it. The code is below:
import os.path
import pyglet
from pyglet.window import key
from openal import *
import time
class Prototype(pyglet.window.Window):
def __init__(self):
super(Prototype, self).__init__(640, 480, resizable=False, fullscreen=False, caption="Test")
self.clear()
self.listener = Listener()
self.types = [".mp3", ".wav", ".flac", ".mp4", ".mpg", ".avi", ".m4a"]
self.types = str(self.types)
self.playlist = []
self.path = input("Enter the path to your music folder.")
self.letter = input("Name of the song? ")
print(os.getcwd())
#list directories
with os.scandir(self.path) as it:
for entry in it:
if not entry.name.startswith('.') and entry.is_file():
name = os.path.splitext(str(os.path.split(entry)[1]))
if self.letter in name[0].lower():
if name[1].lower() in self.types:
self.playlist += [name[0]+name[1]]
## print(self.playlist)
if len(self.playlist) > 0:
for a in range(0,len(self.playlist),1):
print(a,". "+self.playlist[a])
self.index = int(input("select track:"))
self.music = pyglet.media.StaticSource(pyglet.media.load(self.path+"\\"+self.playlist[self.index],streaming=False))
self.player = pyglet.media.Player()
#create an EFX slot for effects
self.slot = EFXslot()
#create a reverb effect
self.effect1 = equalizer()
#mount the effect into the EFX slot
self.slot.set_effect(self.effect1)
#set listener position
self.listener.position = (320,240,0)
#set player position
self.player.position = (160,240,0)
#set rolloff factor
self.player.rolloff = 0.01
#move sound from left to right
for eq in range(0,15,1):
if eq == 5:
#connect a source to output through the EFX slot to apply the effect
self.player.add_effect(self.slot)
pyglet.clock.schedule_interval(self.update, .01)
def update(self,dt):
if self.player.playing == False:
self.player.queue(self.music)
self.player.play()
#draw screen
self.draw()
def draw(self):
self.clear()
def on_key_press(self,symbol,modifiers):
if symbol == key.UP and self.player.volume < 2.0:
self.player.volume += 0.1
print(self.player.volume)
if symbol == key.DOWN and self.player.volume > 0.0:
self.player.volume -= 0.1
print(self.player.volume)
if symbol == key.LEFT:
print(self.player.time)
if self.player.time - 10.0 < 0.0:
self.player.seek(0.0)
else:
self.player.seek(self.player.time - 10.0)
print(self.player.time)
if symbol == key.RIGHT:
print(self.player.time)
get_duration = self.music.duration
if self.player.time + 10.0 > get_duration:
self.player.seek(get_duration)
else:
self.player.seek(self.player.time + 10.0)
print(self.player.time)
time.sleep(1)
#stop player
self.player.stop()
#clean up resources
self.effect1.delete()
self.player.delete()
self.slot.delete()
self.sound.delete()
self.listener.delete()
if symbol == key.ESCAPE:
self.close()
if __name__ == '__main__':
window = Prototype()
pyglet.app.run()
The problem is a bit... bothersome. Pyglet has a number of features for loading different audio formats, but doesn't support more advanced features like EFX. PyLite currently only loads wav files, but has support for advanced features, but the two are not interchangable perse. The good news is its not that hard to load the audio data into pyglet and dump it into a Pylite Buffer, although looking at it a bit I could have made some better adjustments to the BufferSound() handler class. Oh well. Anyway, i've made a few tweaks to PyLite you can make due to a few hiccups along the way, but here's the working script:
import os.path
import pyglet
from pyglet.window import key
from openal import *
import time
class Prototype(pyglet.window.Window):
def __init__(self):
super(Prototype, self).__init__(640, 480, resizable=False, fullscreen=False, caption="Test")
self.clear()
self.listener = Listener()
self.types = [".mp3", ".wav", ".flac", ".mp4", ".mpg", ".avi", ".m4a"]
self.types = str(self.types)
self.playlist = []
self.path = input("Enter the path to your music folder.")
self.letter = input("Name of the song? ")
print(os.getcwd())
#list directories
with os.scandir(self.path) as it:
for entry in it:
if not entry.name.startswith('.') and entry.is_file():
name = os.path.splitext(str(os.path.split(entry)[1]))
if self.letter in name[0].lower():
if name[1].lower() in self.types:
self.playlist += [name[0]+name[1]]
## print(self.playlist)
if len(self.playlist) > 0:
for a in range(0,len(self.playlist),1):
print(a,". "+self.playlist[a])
self.index = int(input("select track:"))
self.music = pyglet.media.StaticSource(pyglet.media.load(self.path+"\\"+self.playlist[self.index],streaming=False))
self.buffer = BufferSound()
self.buffer.channels = self.music.audio_format.channels
self.buffer.bitrate = self.music.audio_format.sample_size
self.buffer.samplerate = self.music.audio_format.sample_rate
self.buffer.load(self.music._data)
self.player = Player()
#create an EFX slot for effects
self.slot = EFXslot()
#create a reverb effect
self.effect1 = equalizer()
#mount the effect into the EFX slot
self.slot.set_effect(self.effect1)
#set listener position
self.listener.position = (0,240,0)
#set player position
self.player.position = (0,240,0)
#set rolloff factor
self.player.rolloff = 0.01
#connect a source to output through the EFX slot to apply the effect
self.player.add_effect(self.slot)
pyglet.clock.schedule_interval(self.update, .01)
def update(self,dt):
if self.player.playing() == False:
## self.player.queue(self.buffer)
self.player.add(self.buffer)
self.player.play()
## print(self.player.playing)
#draw screen
self.draw()
def draw(self):
self.clear()
def on_key_press(self,symbol,modifiers):
if symbol == key.UP and self.player.volume < 2.0:
self.player.volume += 0.1
print(self.player.volume)
if symbol == key.DOWN and self.player.volume > 0.0:
self.player.volume -= 0.1
print(self.player.volume)
if symbol == key.LEFT:
print(self.player.time)
if self.player.time - 10.0 < 0.0:
self.player.seek(0.0)
else:
self.player.seek(self.player.time - 10.0)
print(self.player.time)
if symbol == key.RIGHT:
print(self.player.time)
get_duration = self.music.duration
if self.player.time + 10.0 > get_duration:
self.player.seek(get_duration)
else:
self.player.seek(self.player.time + 10.0)
print(self.player.time)
time.sleep(1)
if symbol == key.ESCAPE:
#stop player
self.player.stop()
#clean up resources
self.effect1.delete()
self.player.delete()
self.slot.delete()
self.buffer.delete()
self.listener.delete()
self.close()
if __name__ == '__main__':
window = Prototype()
pyglet.app.run()
And here's the adjustments to Pylite: line 67
self._lib = ctypes.CDLL(os.getcwd()+'\OpenAL32.dll')
And the BufferSound class:
#OpenAL Sound Buffer
class BufferSound(object):
def __init__(self):
self.channels = 1
self.bitrate = 16
self.samplerate = 8000
self.wavbuf = None
self.length = None
self.formatmap = {
(1, 8) : al.AL_FORMAT_MONO8,
(2, 8) : al.AL_FORMAT_STEREO8,
(1, 16): al.AL_FORMAT_MONO16,
(2, 16) : al.AL_FORMAT_STEREO16,
}
self.alformat = self.formatmap[(self.channels, self.bitrate)]
self.buf = al.ALuint(0)
al.alGenBuffers(1, self.buf)
def load(self,data):
self.wavbuf = data
self.length = len(data)
self.alformat = self.formatmap[(self.channels, self.bitrate)]
#allocate buffer space to: buffer, format, data, len(data), and samplerate
al.alBufferData(self.buf, self.alformat, self.wavbuf, len(self.wavbuf), self.samplerate)
def delete(self):
al.alDeleteBuffers(1, self.buf)
Just replace those and it should hopefully fix any issues.
Mail archive link seems to be dead. Where can i get latest pylite wrapper of Yours? i had it on my old computer, the computer has broken but, it is gone now.
@magurp244
i wanted to test your code with Your openal wrapper. i have done everything accordingly including that i've replaced dlls as well. DO you have a chance of testing ? i m getting this error :
Traceback (most recent
call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python39\test.py", line 4, in <module>
from openal import * File "C:\Users\user\AppData\Local\Programs\Python\Python39\openal.py",
line 1965, in <module>
al = lib_openal()
File "C:\Users\user\AppData\Local\Programs\Python\Python39\openal.py", line 67, in __init__
self._lib = ctypes.CDLL(os.getcwd()+'\OpenAL32.dll') graphic 738 File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\ctypes\__init__.py",
line 374, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\user\OpenAL32.dll' (or one of its dependencies). Try using the full graphic 738 path with constructor
syntax.
Here are the pastebans
1.Player
https://paste.ubuntu.com/p/HzkxgyhcbY/
2.Pylite (editted)
https://paste.ubuntu.com/p/pc2zt6BQGH/
That seems more like a [pathing error]. Be sure to keep the given OpenAL32.dll in the same directory as pylite and your script. It could also be because I had added:
self._lib = ctypes.CDLL(os.getcwd()+'\OpenAL32.dll')
So you could just as easily try:
self._lib = ctypes.CDLL('OpenAL32.dll')
Either that, or we could try using "os.add_dll_directory()".
qmagurp244
i've tried Fİrst two off Your options and modified pylite accordingly. i couldn't get the 3rd option done since i don'T know how to use add_dll_directory() Did You also try this code? does that work for You?
Playing with it a bit, you can leave the CDLL line in Pylite as:
self._lib = ctypes.CDLL('OpenAL32.dll')
Instead, in your script add the add_dll_directory() line to before you import openal, like so:
import os
import pyglet
from pyglet.window import key
os.add_dll_directory(os.getcwd())
from openal import *
Hopefully that should be ok.
Magurp it shows no bug yet but, when i've run the app it shows up the windows message saying 'Test is not responding, close or wait for program to respond'
AudioGames.net Forum → Developers room → Pyglet help
Generated in 0.031 seconds (49% PHP - 51% DB) with 10 queries