Recognizing dictation

Hi, I’m a pretty new programmer but if a I remember right I don’t believe putting the var str in the draw function is efficient.

I want it so when you use the microphone it will print what was said. It will show up in the text(str) but not print.

I wanted to move the str = keyboardbuffer() out of the draw function but not sure what function would recognize speech.

Also is there anyway to set what the keyboard buffer is = to, or clear it with out the hide/show function?

-- Frame Creator

-- Use this function to perform your initial setup
function setup()
    showKeyboard()
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(31, 60, 78, 255)

    -- This sets the line thickness
    strokeWidth(5)

    fill(255, 207, 0, 255)
    text(str, WIDTH/2, HEIGHT/2)
    str = keyboardBuffer()
    -- Do your drawing here
end

function keyboard(k)
    if k then
        print(str)
    end
    -- tried w/o if then statement
end

Codea doesn’t use the microphone. Maybe in a future release.

@dave1707

I understand. However, I can use Siri’s microphone by clicking the button at the bottom left and when I speak this will make my KeyboardBuffer = whatever I said.

I wanted to know if I could make the str update according to that rather than 60 a second.

I didn’t know that, I never played with Siri. One thing you can do is after you show the text in str, hide the keyboard and show it again. That clears the keyboard buffer. If the buffer is nil, don’t update str. Then when the keyboard buffer has something in it, update str. I would have to try Siri to see what you’re actually trying to do.

This worked for me if I understand what you’re doing. Tap the screen to show the keyboard which clears the keyboard buffer.

function setup()
    str=""
end

function draw()
    background(0)
    fill(255, 207, 0, 255)
    if keyboardBuffer()~="" then
        str=keyboardBuffer()
        text(str, WIDTH/2, HEIGHT/2)
    end
end

function touched(t)
    showKeyboard()
end

@dave1707
I’m just playing around with voice recognition.

I thought about creating a program that can create menus by speaking. It’s working so far.

@dave1707

I had one last question. I’ve always had trouble with return values and I’m trying to figure that out here.

I’m trying to get it so when the str == “add frame” it will do VoiceReturn[1]

However, codes doesn’t like VoiceReturn[i] in my code it’s not correct and I can’t run my code.

function Analyze(str)
    for i,v in pairs(VoiceRecognize) do
        if str == v then
            VoiceReturn[i] -- I can't run this
            print(str)
            print("str")
            hideKeyboard()
        end
    end
end

function VoiceInput()
    VoiceRecognize = {
    "add frame",
    "add frame align left"
    }
end

function VoiceCommand()
    VoiceReturn = {
    CommandAddFrame(),
    CommandAlignLeft(),
    }
end
function setup()
    VoiceRecognize = {"add frame","add frame align left" }
    VoiceReturn = {CommandAddFrame,CommandAlignLeft }
    str="add frame"
    Analyze(str)
end

function Analyze(str)
    for i,v in pairs(VoiceRecognize) do
        if str == v then
            VoiceReturn[i]() -- I can't run this
            hideKeyboard()
        end
    end
end


function CommandAddFrame()
    print("function add frame")    
end

function CommandAlignLeft()
    print("function align left")    
end

@dave1707
Thank you so much!!!