Using Speech and Music import
Posted: 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 ?
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 ?