How to make that Nao calculates human answers? - python

The Task: It is planning that Nao should ask humans some questions and give answer variants. The people should give one answer variant per question but after every five question, Nao should say: Ok, you answered on 5 questions and gave 3 correct and 2 incorrect answers. Please, try again.
The realization: The questions and answer variants are realized in the Choreography Dialog but I can't understand how can I call the variable from Python script in the Dialog.
I call the calculated variable in Dialog (QiChat) like this:
topic: ~addition()
language: enu
u:([c]) Yes, it's the correct answer.
%script
p=+1
%script
But how in such case to do that the value of the variable should be understood by QiChat and nao will say the value of variables?
This example nao can't say, it will be missing during dialog.
%script
print p
%script
Such approach to connect dialog and python script doesn't work:
$cnt = %script p %script

Here is a dialog-service template that has dialog linked to some python code; see in the .top file for how to call the Python or get info from it:
u:(set {the} counter [to at] _~numbers)
setting counter to $1
^call(ALMyService.set($1))
u:(["check counter" "what is the counter?"])
So, ^call(ALMyService.get())
c1:(_*) the counter is $1
(this assumes your Python is running in a service; an example of that is also included in that template)

Related

Setting NSSpeechSynthesizer mode from Python

I am using PyObjC bindings to try to get a spoken sound file from phonemes.
I figured out that I can turn speech into sound as follows:
import AppKit
ss = AppKit.NSSpeechSynthesizer.alloc().init()
ss.setVoice_('com.apple.speech.synthesis.voice.Alex')
ss.startSpeakingString_toURL_("Hello", AppKit.NSURL.fileURLWithPath_("hello.aiff"))
# then wait until ve.isSpeaking() returns False
Next for greater control I'd like to turn the text first into phonemes, and then speak them.
phonemes = ss.phonemesFromText_("Hello")
But now I'm stuck, because I know from the docs that to get startSpeakingString to accept phonemes as input, you first need to set NSSpeechSynthesizer.SpeechPropertyKey.Mode to "phoneme". And I think I'm supposed to use setObject_forProperty_error_ to set that.
There are two things I don't understand:
Where is NSSpeechSynthesizer.SpeechPropertyKey.Mode in PyObjC? I grepped the entire PyObjC directory and SpeechPropertyKey is not mentioned anywhere.
How do I use setObject_forProperty_error_ to set it? I think based on the docs that the first argument is the value to set (although it's called just "an object", so True in this case?), and the second is the key (would be phoneme in this case?), and finally there is an error callback. But I'm not sure how I'd pass those arguments in Python.
Where is NSSpeechSynthesizer.SpeechPropertyKey.Mode in PyObjC?
Nowhere.
How do I use setObject_forProperty_error_ to set it?
ss.setObject_forProperty_error_("PHON", "inpt", None)
"PHON" is the same as NSSpeechSynthesizer.SpeechPropertyKey.Mode.phoneme
"inpt" is the same as NSSpeechSynthesizer.SpeechPropertyKey.inputMode
It seems these are not defined anywhere in PyObjC, but I found them by firing up XCode and writing a short Swift snippet:
import Foundation
import AppKit
let synth = NSSpeechSynthesizer()
let x = NSSpeechSynthesizer.SpeechPropertyKey.Mode.phoneme
let y = NSSpeechSynthesizer.SpeechPropertyKey.inputMode
Now looking at x and y in the debugger show that they are the strings mentioned above.
As for how to call setObject_forProperty_error_, I simply tried passing in those strings and None as the error handler, and that worked.

How can I change the format of Python GTK3 SpinButton displayed text?

Basing my code on this allegedly Python-specific documentation example, I have:
def on_output(spin):
adj = spin.get_adjustment()
val = int(adj.get_value())
s = "%02d" % val
print "on_output: %s" % s
spin.set_text(s)
which I connect to my SpinButton's "output" signal. It seems to work when the control is first displayed (shows "00"), but when I click SpinButton's increment button, the formatted value from on_output is overwritten, so e.g. my "01" is shown as plain "1". Looks like another signal or event is causing the control to reformat itself after on_output, but I'm struggling a bit to diagnose. Any experts on GTK3 with Python, please help with debugging suggestions.
Platform is Xubuntu 18.10, Python 2.7, GTK3 3.22.
Wow! If ever there was a case for responding with 'RTFM!' this was it. As very politely pointed out by Alexander Dmitriev, the 'return' statement is missing. In my first attempt, I returned True, but it failed (for some presumably unrelated reason) so I tried False which made no difference. Somehow, the return value got lost after that, and when I re-read the doco 'carefully' I missed seeing it -- we see what we expect to see! I must be getting too old for this hacking game, maybe time to hang up my keyboard. :)

How can I change baselines code output/replay (PPO) on github?

I am trying to run my own version of baselines code source of reinforcement learning on github: (https://github.com/openai/baselines/tree/master/baselines/ppo2).
Whatever I do, I keep having the same display which looks like this :
Where can I edit it ? I know I should edit the "learn" method but I don't know how
Those prints are the result of the following block of code, which can be found at this link (for the latest revision at the time of writing this at least):
if update % log_interval == 0 or update == 1:
ev = explained_variance(values, returns)
logger.logkv("serial_timesteps", update*nsteps)
logger.logkv("nupdates", update)
logger.logkv("total_timesteps", update*nbatch)
logger.logkv("fps", fps)
logger.logkv("explained_variance", float(ev))
logger.logkv('eprewmean', safemean([epinfo['r'] for epinfo in epinfobuf]))
logger.logkv('eplenmean', safemean([epinfo['l'] for epinfo in epinfobuf]))
logger.logkv('time_elapsed', tnow - tfirststart)
for (lossval, lossname) in zip(lossvals, model.loss_names):
logger.logkv(lossname, lossval)
logger.dumpkvs()
If your goal is to still print some things here, but different things (or the same things in a different format) your only option really is to modify this source file (or copy the code you need into a new file and apply your changes there, if allowed by the code's license).
If your goal is just to suppress these messages, the easiest way to do so would probably be by running the following code before running this learn() function:
from baselines import logger
logger.set_level(logger.DISABLED)
That's using this function to disable the baselines logger. It might also disable other baselines-related output though.

Python Function Won't Run At ALL? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am fairly new to the programming world and am wondering why the following code will not only refuse to run, but my python software won't even give me any error messages whatsoever.I'm using Pythonista, an IOS app for python. I can't get the app to run this code (and it won't give me any error messages) and was wondering if it's my code itself, or is it just the application. Any knowledge on this issue would be greatly appreciated.
def starBits():
badMatchups = [Zelda, Cloud, Ryu]
worstMatchups = [Jigglypuff, Villager, Bayonetta]
print(badMatchups)[1:2]
print(worstMatchups)[1:1]
def main():
starBits()
main()
I'm not sure what you expect from this, but it's really funky syntax.
print(badMatchups)[1:2]
print(worstMatchups)[1:1]
If those slices are subscripts for the lists, you need them inside the call to print:
print(badMatchups[1:2])
print(worstMatchups[1:1])
By the way, do you realize that [1:1] is an empty slice? The second number is the first position not included. You may need
print(badMatchups[1:3]) # two elements
print(worstMatchups[1:2]) # one element
Also, are those elements external variables, or are they supposed to be literal names? If the latter, then you have to put them in quotation marks.
badMatchups = ["Zelda", "Cloud", "Ryu"]
worstMatchups = ["Jigglypuff", "Villager", "Bayonetta"]
With this change, the code runs; I hope it's what you want.
Can't get it to run? Reality check time ...
Full code, changes made:
def starBits():
badMatchups = ["Zelda", "Cloud", "Ryu"]
worstMatchups = ["Jigglypuff", "Villager", "Bayonetta"]
print(badMatchups[1:3])
print(worstMatchups[1:2])
def main():
starBits()
main()
Output:
['Cloud', 'Ryu']
['Villager']

turn displays on with python under Windows 7 64bit

I'm trying to turn displays on using python. Found this code very useful but the problem is that it is turning display on for a brief moment and after like 1 second all displays are still 'entering power-save mode'. How can I make this 'power on' feature permanently?
Thanks for the hint, martineau! Simple sending message like that will not work:
win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1)
I also tried:
ctypes.windll.user32.SetCursorPos(100, 20)
and
pygame.mouse.set_pos((random.choice(range(600)), random.choice(range(600))))
to utilise mouse, but this is nothing when compare to:
win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE|win32con.MOUSEEVENTF_MOVE,100,20)
mouse_event did the trick as explained here

Categories