Showing posts with label speech. Show all posts
Showing posts with label speech. Show all posts

Sunday 26 December 2021

Hug Avoider 4 - micropython, Eggbot and speech

The last of the posts on the Hug avoider and the 4Tronix's Eggbit



4Tronix's Eggbit (in fact I bought three of them https://shop.4tronix.co.uk/collections/bbc-micro-bit/products/eggbit-three-pack-special  :-) recently) is a cute add-on for the microbit. In three previous posts I looked at eggbit using microcode to  produce a hug avoider - warns when people at too close.



In this post using the buttons and adding (via Microbit V2 with its speaker) simple speech


1. Buttons

Pins for the buttons
  • pin8 - Green button
  • pin12 - Red button
  • pin14 - Yellow button
  • pin`6 - Blue button

    if pin12.read_digital()==1:
        #Red Button
        blank_it()
    if pin8.read_digital()==1:
        #Green button
        startingMessage()
    if pin14.read_digital()==1:
        #Yellow button
        rainbow()
    if pin16.read_digital()==1:
        #Blue botton
        display.show(Image.ASLEEP)

2. Speech


    mess1 = [
    "This is the hug avoide",
    "please keep back",
]
# Take from https://microbit-micropython.readthedocs.io/en/latest/tutorials/speech.html
    for line in mess1:
        speech.say(line, speed=120, pitch=100, throat=100, mouth=200)
        sleep(500


The speech is difficult to hear but is fun and there are possibly ways to improve this starting with the information on  https://microbit-micropython.readthedocs.io/en/latest/tutorials/speech.html



3. Overall

from microbit import *
from machine import time_pulse_us
import neopixel, speech

sonar =pin15
sonar.write_digital(0)
fireled=neopixel.NeoPixel(pin13,9)

def rainbow():
    fireled[0] = (255, 0, 40)
    fireled[1]=  (255,165,0)
    #block=yellow
    fireled[2] = (255,255,0)
    #block=green
    fireled[3] = (0,255,0)
    #block=blue
    fireled [4] = (0,0,255)
    # block=indigo
    fireled[5] = (75,0,130)
    # block=violet
    fireled[6] = (138,43,178)
    #block=purple
    fireled[7] = (255,0,255)
    fireled.show()

def blank_it():
    for j in range(8):
        fireled[j] = (63, 0, 0)
    fireled.show()

def howfar():
    sonar.write_digital(1)
    sonar.write_digital(0)

    timeus=time_pulse_us(sonar,1)
    echo=timeus/1000000
    dist=(echo/2)*34300
    sleep(100)
    return dist

def startingMessage():
    mess1 = [
    "This is the hug avoide",
    "please keep back",
]
# Take from https://microbit-micropython.readthedocs.io/en/latest/tutorials/speech.html
    for line in mess1:
        speech.say(line, speed=120, pitch=100, throat=100, mouth=200)
        sleep(500)

def buttonplay():
    if pin12.read_digital()==1:
        #Red Button
        blank_it()
    if pin8.read_digital()==1:
        #Green button
        startingMessage()
    if pin14.read_digital()==1:
        #Yellow button
        rainbow()
    if pin16.read_digital()==1:
        #Blue botton
        display.show(Image.ASLEEP)
  
while True:
    buttonplay()
    dist=howfar()
    if dist>30:
        pin2.write_digital(1)
        pin0.write_digital(0)
        display.show(Image.HAPPY)
    else:
        pin2.write_digital(1)
        pin0.write_digital(1)
        blank_it()
        speech.say("back away please", speed=120, pitch=100, throat=100, mouth=200)
        display.show(Image.ANGRY)




All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Saturday 18 July 2020

Speech Recognition in Scratch 3 - turning Hello into Bonjour!

The Raspberry Pi Foundation recently released a programming activity Alien Language, with support Dale from Machine Learning for Kids, that is a brilliant use of Scratch 3 - Speech Recognition to control a sprite in an alien language. Do the activity, and it is very much worth doing, and it will make sense! I  would also recommend going to the machinelearningforkids.co.uk site anyway it is full of exciting things to do (for example loads of activities https://machinelearningforkids.co.uk/#!/worksheets ). Scratch 3 has lots of extensions that are accessible through the Extension button in the Scratch 3 editor (see below) which add new fun new blocks to play with.



The critical thing for this post is Machine Learning for Kids have created a Scratch 3 template with their own extensions for Scratch 3 within it https://machinelearningforkids.co.uk/scratch3/. One of which is a Speech to Text extension (see below). You must use this one not the standard Scratch 3.



My idea is to can I set it to react one way when I say "hello"; then say "french" and then say "hello" it says "Bonjour". Two other extensions are needed along with the Speech to Text one - one for speech to text and the translate shown below.



Ok, so to the fun bit. The listen and wait, and when I hear blocks are the key new blocks, and they do what they say. The three sets of the code are ones I used for this activity.




Thank you to Machine Learning for Kids for creating such a brilliant Scratch extension - this is well worth a play with.



All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Monday 20 August 2018

Speech with EduBlocks on BBC microbit

The microbit is a great piece of kit, not least of which because of the range of programming languages and tools that can be used with it - officially JavaScript and Python and but there is also a range of third-party ones. A useful place to look for what languages/tools  are available is http://microbit.org/code-alternative-editors/; listing both official and third-party tools (there was a few I wasn't aware of ). One I was aware and meaning to play with, is the brilliant Edublocks by Josh Lowe (@all_about_code) or more  specifically in this post Edublocks for BBC Micro:bit (https://microbit.edublocks.org/).



Edublocks for the microbit (and Edublocks in general) allows graphical blocks of code, in a similar way to languages such as Scratch, to be dragged and dropped into places. That in itself would be great, but the really useful thing here is though, whilst doing it you are actually producing a Python program (technically in the microbit case micropython)- a good way (as others have said before e.g https://www.electromaker.io/blog/article/coding-the-bbc-microbit-with-edublocks ) of bridging the gap between block based programming tand text-based programming language (ie. Python). Added to this is the support for Python on the microbit and the things like speech, access the pins and neopixels you have a really useful and fun tool. 





Talk is cheap (sort of!)
The project shown here is getting the microbit to 'talk' using speech. I have attached a microbit to Pimoroni's noise bit for convenience (https://shop.pimoroni.com/products/noise-bit but equally, alligator wires and headphones could be used (https://www.microbit.co.uk/blocks/lessons/hack-your-headphones/activity ). The routine below allows when button A on the microbit is pressed the Microbit (through a speaker) to say Hello, B say Good bye and when both pressed Now what ? Simple but fun.



The equivalent Python code
They are essentially the same.


Here is a video of it in action:






Thoughts.

As you might have gathered I think this Edublocks for the microbit is a fantastic tool. I am planning my new experiments with it now- coming soon to this blog. Edublocks for the microbit is not all Edublocks can do, the project itself can be found at https://edublocks.org/ is well worth a look. For playing with the microbit for the first time with Python I would recommend Edublocks for the microbit  https://microbit.edublocks.org/


All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Thursday 27 August 2015

OhBot and Detecting Faces

With a bit of time off, I had a chance to play with the Ohbot (see Previous related links below) a little more. My son and I played with trying to find could we get it to say hello if there is a face on camera but otherwise make it move randomly as if it was looking.

We based the code on the examples codes that can be found at the OhBot website (http://ohbot.weebly.com/).


The video below shows it in action.



Previous related posts




All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with.

ChatGPT, Data Scientist - fitting it a bit

This is a second post about using ChatGPT to do some data analysis. In the first looked at using it to some basic statistics  https://robots...