2019-01-31 03:10:15

So I wanted to be able to get the user to hear stuff from their screen reader, and doing a bit of research yielded Tolk, direct download link
I looked at the tolk.h file, and it's pretty understandable. My issue? Well, uh, I can't import it? Where do I paste in the modules to be imported/what exactly do I paste? Do I paste in the entire src folder somewhere? Do I paste in the .h file somewhere? Highly doubtful... Does the script I run require the lib folder within the directory it's run from? If so, where do I paste the library to if I want the console, you know, the thingy that pops up after you type in python into the running prompt, to not give me errors stating that it can't find a module named Tolk.

2019-01-31 05:03:10

You put tolk.py and tolk.dll in the same location as your script.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2019-01-31 21:48:00 (edited by amerikranian 2019-01-31 21:49:20)

So I have a couple of questions.
1: Say I want to use pygame for my window creation, would it restrict me from using certain functions in python itself? Pretty silly, I know, but I want to check.
2: What is the difference between a class and a module? I mean is class a module if you save it to a file? Could a class  be considered a module? Are there different rules concerning the variable scope between the two?
3: Is it normal if I create a pygame window and after running it getting the This program stopped responding statement? I'm asking because the window does nothing, it just sits there until you kill it with task manager.
@Ethan, thanks for the tip, gonna try it after I get home.

2019-01-31 22:52:13

1: no, pygame does not restrict your usage of anything. You are free to use whatever you like (even other event handlers alongside the main one) but I wouldn't if I were you.
2: a module is one of three things:
* a .py file that can be imported with the import statement
* a collection of python files that can be imported with the import statement (i.e. the numpy package is a large collection of python files that is imported when you use import numpy)
* A DLL or Python extension written in another programming language that is capable of both interfacing with Python and creating DLLs that are linked against the Python interpreter you are using
In the case of the third possibility, the extension must be linked against the exact Python version your using (i.e. you can't use an extension written for Python 3.6 in Python 3.7 and vice versa). That is the major downside to extensions written in other programming languages, but they are still very useful.
3: yes, it is. The reasons I can think of for the program not doing anything are quite a lot, but I'll give the most common:
* you do not have an event handler to process events (i.e. mouse buttons, keyboard key presses/releases, etc.) or you have one but it is not running
* Another function call has blocked the main Python thread and the function has not returned control
A typical pygame event loop looks like:

def event_loop():
    pygame.event.pump()

A good practice that you should adopt when making a game is to only have one event handler. You don't need tons of while loops for your event handler to function properly, something like a background thread that calls your event handler over and over is fine. The more event handlers you have running simultaneously the higher the risk that you will "lose" an event; that is, an event is sent by the OS, but is never caught because an event handler didn't execute fast enough because another was hogging the thread. So make an event handler that places event data in a globally accessible structure and reference that. This advice becomes especially important when you use frameworks like SDL2.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2019-02-02 20:07:11 (edited by amerikranian 2019-02-02 23:49:05)

So @Ethin, I think I figured out what you meant by dlls not working. I currently have an issue with creating a menu class and using Tolk to speak it. The tolk works great in the main file, but as soon as I try and pass it to my loop for the menu things break, badly. See what I mean by going Here
I admit, even that bit of code took me a bit to test and debug, but now the program simply closes without anything. No good bye, no errors to help me, nothing as far as I can see, until I run the damn thing through the command line prompt.
To hopefully get the same error as me, open cmd, do cd and then the path to the folder where your copy of python3.exe is located at, then do py -3 path to myscript.py.
If you're getting the OS 126: Can't find the module, error, good. We're on the same page. Thing is, Tolk works just fine in the normal file. I checked my pygame functions, and they were all the same as the documentation found right here, as far as I know.
The problem is that this is something I can't debug do to the lack of knowledge. I was gonna use a menu to create guess the number and higher or lower, just to see how my skills fair up against multiple files.
So tips? Suggestions? Anything? I'm truly stumped. I checked all I knew to check. Indentation seems to be fine, I didn't forget any colons as far as I know, but the run function in the menu class seems to disagree. I've spent 2 hours on it with no headway, so I'd appreciate any help.

2019-02-03 00:22:59

do you have the tolk.dll file in the same directory as your script? Tolk.py should be in there as well.b

If you have issues with Scramble, please contact support at the link below. I check here at least once a day, so this is the best avenue for submitting your issues and bug reports.
https://stevend.net/scramble/support

2019-02-03 04:11:19 (edited by amerikranian 2019-02-03 12:58:43)

I do. I have the Tolk files in there. Thing is, the Tolk works in the main file, and in the menu file if I add it to any other function but run. When I add it to run function, the program crashes, though it does the same without it, as well. My code is short, and I really think that something's is wrong with my run function. It's in the link in my last post of the thread, but I'll post the code in here, as well.

 def run(self, Tolk):
  choice = 0
  if len(self.menu_choices)==0:
   return -2
  Tolk.output(str(self.menu_choices.get(choice)), True)
  for event in pygame.event.get():
   if event.type == KEYDOWN:
    if event.key == K_UP and choice>0:
     choice-=1
     Tolk.output(str(self.menu_choices.get(choice)), True)
    elif event.key == K_DOWN and choice<len(self.menu_choices)-1:
     choice+=1
     Tolk.output(str(self.menu_choices.get(choice)), True)
   pygame.event.pump()

  If anybody could shed some light on here I'd be extremely grateful.
Also, you may ask me how am I sure that the bug is in the run function? It's simple. I tested out every other function, passing Tolk as it's params, and it worked like a charm. I think my issue is not with Tolk, but with pygame itself. I wouldn't be surprised if it's a simple matter of capitalization.

2019-02-03 22:07:43 (edited by amerikranian 2019-02-03 22:10:25)

Right, so more info if yall can help me here.
I think there is a problem with the Tolk file I got. The following script works like it should:

import time
import pygame
import Tolk
from pygame.locals import *
Tolk.load()
pygame.init()
screen = pygame.display.set_mode((150, 50))
pygame.display.set_caption("Test program.")
time.sleep(6)
Tolk.output("Testing.")
time.sleep(4)
Tolk.output("Testing again.")
time.sleep(4)
Tolk.output("Testing a third time because why not.")
time.sleep(4)

The program goes unresponsive, but that's expected. The important bit is Tolk reading the messages and passing them through. The following script doesn't work, however.

import time
import pygame
import Tolk
from pygame.locals import *
Tolk.load()
pygame.init()
screen = pygame.display.set_mode((150, 50))
pygame.display.set_caption("Test program.")
while 1:
 for event in pygame.event.get():
  if event.type==KEYDOWN:
   if event.KEY==K_LEFT:
    time.sleep(3)
    Tolk.output("Testing testing 1 2 3.")
    time.sleep(3)
    break

This version of the code also doesn't work:

import time
import pygame
import Tolk
import sys
from pygame.locals import *
Tolk.load()
pygame.init()
screen = pygame.display.set_mode((150, 50))
pygame.display.set_caption("Test program.")
while 1:
 for event in pygame.event.get():
  if event.type==QUIT:
   sys.exit(0)
  if event.type==KEYDOWN:
   if event.key==K_LEFT:
    Tolk.output("Exiting.")
    time.sleep(3)
    sys.exit(0)
 pygame.event.pump()

The error I get from this is this:

    import Tolk                                                                 
  File "C:\Users\amerikranian\Desktop\python\Tolk.py", line 11, in <module>      
    _tolk = cdll.Tolk                                                           
  File "C:\python3\lib\ctypes\__init__.py", line 426, in __getattr__            
    dll = self._dlltype(name)                                                   
  File "C:\python3\lib\ctypes\__init__.py", line 356, in __init__               
    self._handle = _dlopen(self._name, mode)                                    
OSError: [WinError 126] The specified module could not be found                 

Again, tips, suggestions, anything? You can try and upload your version of Tolk, see if that fixes things, I'm using windows 64.

2019-02-04 00:21:38 (edited by Hijacker 2019-02-04 00:22:38)

Hi,

looks like a problem which encounters directly when importing Tolk. Please make sure you're running both scripts with the same python version and from within the same working directory. I often encounter things like a virtual environment within one project which is working fine, and the global installation within a separate script directory which doesn't work, but you'll invoke both scripts by typing "python script.py". Python 2 and Python 3 might work differently here as well, even though they might both be callable by using "python script.py". If you got python 3 with the launcher installed, try

py -3 script.py

instead, or py -2 if you want to use python 2 respectively.
This doesn't seem to be an issue regarding the scripts you provided though. The question more likely is which environment settings differ from running the first script to running the second and third one, because the first one works and the other two don't. I'd guess you need to copy certain dll files over to the folder the second and third script are running in which are currently present within the folder where the first script can be found.
Best Regards.
Hijacker

2019-02-04 01:47:16 (edited by amerikranian 2019-02-04 02:01:32)

That's the thing: The script is in the exact same folder as the other ones were. Hell, it's even in the same file! The problem is encountered only when I try and do loops, which crashes the program. The scripts work fine, I used sys.exit(0) to proove it and commented out Tolk lines of code. I have Tolk.dll and Tolk.py, and they work beautifully, as long as I don't use any loops, but I can build minimal things with that.
I only got 1 script. 1 script that I use, and another one that imports my menu class, is commented out. I do the exact same thing, I pasted the scripts from the file as I wrote the damn things.
I also do everything just like I normally do: That is, cd c:\python3, then py -3 and then my script paths. It's just that one script works and the other one doesn't.
I have no clue as to why it does it. If you could download Tolk from here and run my scripts provided you have python 3 and pygame then post on here about the results I'd be extremely grateful. The worst thing that could happen is you not getting the same error, as it would mean that something is broken on my end.
If you don't have pygame but you have pip installed, just do pip install pygame.
Edit: Somebody also asked me why can't you use accessible_output? Great idea! Except there's a problem. I don't have a module named braille, even though it is in the damn thing's folder, so it should see it...
By this point I'm willing to try anything. If you think you can guide me through setting up accessible_output, go ahead. I'll take anything that functions as speech, as I, go figure, know little to nothing about this area of coding. Hell, this is as far as I ever gotten with any other language besides bgt.
Edit 2: The issue still persists:
I redownloaded Tolk because the link in post 26 no longer works. Cool, right? Nope. It fixed literally nothing. Is anybody else using Tolk with pygame, or am I just a fool for trying it?

2019-02-04 03:32:00

I don't think you need to pass Tolk to functions, as it acts as a global class. Also remember to include the screen reader driver dll's from the tolk archive in /lib/x64 if your using the 64 bit version, or /lib/x32 for 32 bit.

In this example you gave:

import time
import pygame
import Tolk
from pygame.locals import *
Tolk.load()
pygame.init()
screen = pygame.display.set_mode((150, 50))
pygame.display.set_caption("Test program.")
while 1:
 for event in pygame.event.get():
  if event.type==KEYDOWN:
   if event.KEY==K_LEFT:
    time.sleep(3)
    Tolk.output("Testing testing 1 2 3.")
    time.sleep(3)
    break

In line 12 you put KEY in all caps, which it won't recognise so you can't start the tts test, also putting in the sleep functions seems to mess with it. I'm running it with python 2.7, it was pretty unresponsive, but did work if holding or repeatedly tapping left. I adjusted it abit and this seems to work:

import pygame
import Tolk
import sys
from pygame.locals import *

pygame.init()

Tolk.load()
screen = pygame.display.set_mode((150, 50))
pygame.display.set_caption("Test program.")
while 1:
 for event in pygame.event.get():
  if event.type==KEYUP:
   if event.key==K_LEFT:
    Tolk.silence()
    Tolk.output("Testing testing 1 2 3.")
   elif event.key==K_ESCAPE:
    Tolk.unload()
    pygame.quit()
    sys.exit(0)
  pygame.display.update()

I'm going to go back to being face punched by a cold now...

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2019-02-04 04:26:54 (edited by amerikranian 2019-02-04 04:32:18)

First, thanks for taking the time to answer despite the cold. Second, I'm afraid we still have the persisting 126, can't find the module errors when running your example on my end. Would you mind uploading your version of Tolk assuming you didn't download the one I linked to in post 35?
I have the Tolk.py from the src/python folder and the Tolk.dll from bin/64 folder as well.
As for screenreaders being included, I have both nvda and sapi64.dlls in the same folder I have my script, Tolk.dll, and Tolk.py files. Is that all I need to do?
I'm also using python 3.7.2 and am on windows 8 if my memory serves me correctly, python is grater then 3.6.4, at least.

2019-02-04 05:15:46

I'm actually using the x86 Tolk binaries, they should work just as well on an x64 windows platform, so you could try swapping those over and see if it makes a difference, and yeah having them in the same folder should do it, either that or it could be something with your environment setup. You can download the files I used [here], for the 126 error other posts around suggest installing Visual C++ redistributables for [2013] or [2015],  you could also try downgrading to earlier versions of python to see if that works.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2019-02-04 17:18:29

Another idea before getting into experimentation stage myself, did you try inserting the errorneous script into an interactive python prompt line by line to see if the same error pops up as soon as the tolk import happens? Maybe this one will fix your problem. In the end there is still the possibility that python 3 is at fault here and raises the wrong error message here, so something could theoretically mess the stack trace up here. You can track this problem down by using the previously mentioned method of interpreting each line after another and see where exactly the error shows up.
Best Regards.
Hijacker

2019-02-04 21:18:19

@post 38:
I will try your suggestions as soon as I get home, which should be in a little over 2 hours.
@post 39. Thing is, I can't do the method described. I don't have the Tolk library installed, I only have the files. There's no setup.py or anything, and I don't know how to install packages manually. Thing is, the error doesn't happen if my program has no loops. It only happens if there are loops of any sort. Furthermore, the interactive prompt will simply say "No module named Tolk", where as my script gives me error pertaining to the Tolk file itself. The error can be found in post 33.

2019-02-04 21:55:55

The loop problems from what I can see aren't caused by Tolk. There are a few logic errors.

In the menu module you haven't imported pygame. For every module you import that module needs to import required modules. K_UP and K_DOWN are defined in the pygame module itself, so those need to be pygame.K_UP and pygame.K_DOWN.

The run function iterates through the event queue, which is fine. However as soon as the event queue is empty the program will stop executing. To fix this wrap the repeating menu logic  (including the event queue iteration) in a while loop.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.

2019-02-05 00:44:45 (edited by amerikranian 2019-02-05 00:46:00)

@post 41, thank you for the info.
@post 38: Right, your example gave the same results. Furthermore, when I did pip install tolk and tried importing the thing it gave me an error about the handler module not being there, and I checked, it is in the same folder as __init__.py. So yeah, I think it's my setup.
As for c++, I had the 2017 distribution, so I couldn't install 2013 and 2015 because they gave me "the newer version is better than the product" message.
So now what do you suggest me try? Could it be the problem with my python directory? It's in c:\python3 right now. I'm pretty sure there is no multiple python versions on my PC because when I go to programs and have an option to uninstall them I have the python launcher and python3.7.2, nothing else. I really don't wana go back to earlier versions if I can help it.

2019-02-05 01:50:54

Hm, try putting the following code at the beginning of your script, before you import Tolk:

import sys
import os

#check the current working directory
print(os.getcwd())

#get the current directory of your script
dir_path = os.path.dirname(os.path.realpath(__file__))

#set the current working directory to your script
os.chdir(dir_path)

If the working directory isn't where your script is, then it may not be able to find the DLL to load it. The code above should set the current working directory to the script itself, if you run it directly.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2019-02-05 02:35:35

Yea! Alridy! it works! Any idea why the script wasn't in it's default directory originally?
Why do I need to do pygame.display.update() if I'm planning to only use the audio? Also, you're right, the input is slightly delayed. Is it because of the way the pygame processes events? Or is it do to the way you and I coded it. If if it's the ladder, I would appreciate any tips to improve the the responsiveness. It's fine for what I have in mind, but for games like simon I would like some faster reactions.

2019-02-08 21:19:38

So an update: I've figured out the delay issue, I think. I have built several small projects, couple of dice games to be exact, and I think I'm ready to add in another layer, sound.
I have done some research, and a popular library to use in here is sound_lib. Trouble is, there's just code. While I can go look through it and try and figure it out, I was wondering if anybody had an example of how to use sound_lib, as searching for docs for sound_lib didn't produce promising results.

2019-02-08 22:04:06

I did notice that in your code you call the pygame event pump function unnecessarily. It could be that function since you're calling it a lot.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.

2019-02-09 01:27:23

@Post 46, I thought pygame.event.pump was for keeping the event list clean and prevent it from filling up? Do let me know how do I not use it accessively.

2019-02-09 02:53:21 (edited by magurp244 2019-02-09 03:14:52)

If you run your script from another directory, it would use your current directory as the working one, for example:

C:\yourdir> python yourscript.py

This would make the current directory where you run your script the current working directory, but this:

C:\> python yourdir/yourscript.py

Would make C: the working directory, and not the directory of the script and the files it contains. I'm not sure if a misconfigured IDE like notepad++ could cause an import issue like this, but its something to keep in mind. pygame.display.update() is also more to make the window less janky and more responsive when moving it around. Even if your not using the window or displaying things, it still creates a window and should be considered a matter of best practice to help keep things smooth.

If your going with the example script I used there shouldn't be much of a delay exactly, I changed it so when a key is released it plays the string, as opposed to pressed. This way, if someone holds down the button it won't spam the string and cause playback issues, but it won't trigger until you let go of the key. There are other ways of writing it to handle on key presses, but that was just for that particular example. Pygame can also handle 2D audio, although i'm going to assume you'd prefer 3D audio. I've been meaning to look into a less complex way of setting up and using OpenAL bindings, if your interested in that or any examples for pygames audio I can put something together.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2019-02-09 04:11:12

Wild 2D audio would be nice for a bit, I feel like I will be doing myself a disservice.  I feel like it’s much better to pick a set of tools and stick with them, rather than pick a set of tools and then switch to new ones later.  I would appreciate any tips and/or instructions you can offer downloading the library and or using it.

2019-02-09 04:46:36 (edited by magurp244 2019-02-09 04:53:55)

Like with programming languages in general, learning one can help you better understand and use others. Think of it more as gaining experience, it could prove useful in the future depending on your needs. Anyway, here's an example of Pygames mixer:

import pygame
from pygame import mixer
import sys

def Example():
#initialize pygame
    pygame.init()
#initialize sound mixer
    mixer.init()
#create display
    window = pygame.display.set_mode([640,480])
#load sound
    sound = mixer.Sound('tone5.wav')

#main update loop
    while True:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
            #if space is pressed, play sound
                if event.key == pygame.K_SPACE:
                    sound.play()
            #if escape is pressed, quit
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit(0)

    #update window
        pygame.display.update()

Example()

You can check how many instances of the sound are currently playing by using "sound.get_num_channels()", which can help you put a cap on it to prevent any overlap. You can also find the documentation for playing individual sounds and streaming sounds [here] and [here] respectively.

For OpenAL, you can download my example pack [here], but reflecting on it you don't actually need to install Pyglet to use it. What you do is take the python dependancy files: lib_openal.py, lib_alc.py, and lib_efx.py, and put them in the working directory of your script along with OpenAL32.dll, then import them. In the examples included in the OpenAL pack the imports are for a Pyglet install like so:

from pyglet.media.drivers.openal import lib_openal as al
from pyglet.media.drivers.openal import lib_alc as alc

But if the scripts are just in your working directory you can cut straight to:

import lib_openal as al
import lib_alc as alc

So when using the examples just change the imports appropriately. The examples come with OpenAL32.DLL already, but if you need to get it elsewhere or the latest version go to [OpenAL-Soft] and download the latest release, which is currently 1.19.1, unpack it and head into the /bin/x32 or /bin/x64 directories, depending. Rename either of the soft_oal.dll files to OpenAL32.dll, and copy it to your working directory with the py scripts, and you should be good to go.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer