Re: Pyglet help

Hm, pyglets media library can load audio fine without a window loaded, so you could get away with using just the command line with no hotkeys like so:

import os
import pyglet
os.add_dll_directory(os.getcwd())
from openal import *
import time


listener = Listener()

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]]


if len(playlist) > 0:
    for a in range(0,len(playlist),1):
        print(a,". "+playlist[a])

index = int(input("select track:"))

music = pyglet.media.StaticSource(pyglet.media.load(path+"\\"+playlist[index],streaming=False))

buffer = BufferSound()
buffer.channels = music.audio_format.channels
buffer.bitrate = music.audio_format.sample_size
buffer.samplerate = music.audio_format.sample_rate
buffer.load(music._data)

get_duration = music.duration

player = Player()

player.add(buffer)
player.play()

while player.playing() == True:
    print("\nTrack:",playlist[index],"\nPosition:",player.seek,"\nVolume:",player.volume)
    option = input("\n0. Rewind\n1. Fast Forward\n2. Volume Up\n3. Volume Down\nSelect option:")

    try:
        option = int(option)
    except:
        option = 5

    if int(option) == 0:
        if player.seek - ((1.0/get_duration)*10) < 0.0:
            player.seek = 0.0
        else:
            player.seek = player.seek - ((1.0/get_duration)*10)

    elif int(option) == 1:# and (player.seek/get_duration)*10 > 1.0:
        if player.seek+((1.0/get_duration)*10) > 1.0:
            player.seek = 1.0
        else:
            player.seek = player.seek+((1.0/get_duration)*10)
            print(player.seek,((1.0/get_duration)*10))

    elif int(option) == 2:
        if player.volume < 2.0:
            player.volume += 0.1
            print(player.volume)

    elif int(option) == 3:
        if player.volume > 0.0:
            player.volume -= 0.1
            print(player.volume)


player.stop()

#clean up resources
player.delete()
buffer.delete()
listener.delete()

Now, if you want to use hotkeys like the arrow keys, you will need a pyglet window, but the window itself isn't screen reader friendly. You can input text and stitch in TTS support with Tolk, but it can be cumbersome and hit or miss. WxPython is easier to work with when it comes to TTS, and you could hook in hotkeys with it, you could even use its convenient open file widget. The direct keyboard actions though can be a bit finicky, but if you pull in pyglet for format loading with PyLite to do playback, it would probably give the best results. Alternatively, you could flesh out the command line version and use that as is.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector

Reply via email to