Using Speech and Music import

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
Tony
Posts: 2
Joined: Sat Oct 22, 2016 12:49 pm

Using Speech and Music import

Post by Tony » Sun Oct 23, 2016 5:52 pm

Hi
This works ok :- (it plays the tune merry_xmas)
........
from microbit import *
# import speech
import music
# play Merry Christmas
merry_xmas = [
'd4:5', 'g:5', 'g:2', 'a:3', 'g:2', 'f#:4', 'e:4', 'e:4',
'e:4', 'a:4', 'a:3', 'b:3', 'a:2', 'g:4', 'f#:5', 'd:4',
'd:5', 'b:5', 'b:2', 'c5:2', 'b4:2', 'a:5', 'g:3', 'e:4',
'd:5', 'd:3', 'e:2', 'a:5', 'f#:4', 'g:5',
'd:6', 'g:2', 'g:5', 'g:4', 'f#:4',
'f#:4', 'g:3', 'f#:4', 'e:3', 'd:4',
]

while True:
if accelerometer.was_gesture('left'):
# speech.say("happy Christmas")
music.play(merry_xmas)

But if I put in the lines like this :- ( import speech and speech.say("happy Christmas"))
from microbit import *
import speech
import music
# play Merry Christmas
merry_xmas = [
'd4:5', 'g:5', 'g:2', 'a:3', 'g:2', 'f#:4', 'e:4', 'e:4',
'e:4', 'a:4', 'a:3', 'b:3', 'a:2', 'g:4', 'f#:5', 'd:4',
'd:5', 'b:5', 'b:2', 'c5:2', 'b4:2', 'a:5', 'g:3', 'e:4',
'd:5', 'd:3', 'e:2', 'a:5', 'f#:4', 'g:5',
'd:6', 'g:2', 'g:5', 'g:4', 'f#:4',
'f#:4', 'g:3', 'f#:4', 'e:3', 'd:4',
]

while True:
if accelerometer.was_gesture('left'):
speech.say("happy Christmas")
music.play(merry_xmas)
.......

The first time the program runs the speech in heard, followed by the music,
But, then on subsequent time it says “happy Christmas” but you do not hear the tune “merry_xmas”
It must be going through the program ok, in that if you wait for the time it would of taken to play the tune, then shake the microbit, it then says “happy christmas again”
So why do I not hear the tune, after the second time I shake the microbit ?

fizban
Posts: 24
Joined: Mon Oct 24, 2016 2:32 pm

Re: Using Speech and Music import

Post by fizban » Mon Oct 24, 2016 2:34 pm

This might be related to a reported bug: https://github.com/bbcmicrobit/micropython/issues/335

Tony
Posts: 2
Joined: Sat Oct 22, 2016 12:49 pm

Re: Using Speech and Music import

Post by Tony » Mon Oct 24, 2016 4:58 pm

Thanks, for replying
That’s almost certainly the problem I have.
Spent silly amount of time, wondering why / what I was doing wrong.
Didn’t make sense.
It’s not that it is important, just that I like to know why
I did search for bug report, but didn’t find that one.
So at least I know it not me.

Post Reply