This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Xerxeth's profile picture

Force Text Input?

Started by Xerxeth, 24 July 2013 - 10:14 PM
Xerxeth #1
Posted 25 July 2013 - 12:14 AM
ComputerCraft Version: [1.53]

Mod Pack: "Direwolf20_1_5 v1.0.0"

Hey pros,

So I've been playing around ComputerCraft, and I've noticed that within Direwolf20's 1.5 pack, it includes "MiscPeripherals". (Forum Link, here.) There was one block that caught my attention, the Speaker. With an Advanced Computer, running the program "speak" allows you to type in any text, then it will execute an audible text-to-speech. Playing around with this gave me a lot of ideas, and I don't know how I would code any of it. I've looked around for a specific API for the speaker itself, nothing, and I've tried already existing API's and shell.run's. (Perhaps I'm not familiar enough with Lua to properly utilize them.)

Doing a shell.run of "shell.run("speaker", print("Hello World"))" Would print "Hello World", and THEN start up the speak program. What I was hoping it would do is run speak, it would input "Hello World", then it would text-to-speech it.

Is there a way to input text by code into an already existing program? Or could anyone be specific on how you would create API for such a peripheral?

I was thinking of things like:
speaker.readSpeed() | Change the text-to-speech reading speed. | Example: speaker.readSpeed(0.5) –Slow voice.
speaker.readText() | Input text to be read out loud. | Example: speaker.readText("Hello World.") –Would text-to-speech, "Hello World."
speaker.speechAudio() | Change the volume level of the text-to-speech. | Example: speaker.speechAudio(10) –Loudest.

So thinking of a small test program that would be fun to utilize this would probably be something like…

term.setCursorPos(14,2)
print("Test Speech")
term.setCursorPos(14,3)
print("———–")
print(" ")
sleep(0.7)

term.setCursorPos(10,6)
speaker.readText("Hello User, what would you like to do?")
textutils.slowPrint("Hello User, what would you like to do?")

Here are some images of the speaker:

Here it is under MiscPeripherals in the Creative menu.


Here is the speaker placed in the world.


On the left advanced computer, the speaker is behind it.


And this is running "speak", typing in "Hello World", and a voice will read it out loud.

Any help or ideas will be greatly appreciated.



Thanks,
Xerxeth
Grim Reaper #2
Posted 25 July 2013 - 12:45 AM
I'm not familiar with the speaker peripheral, but in your shell.run call, try the following instead:


shell.run ("speaker", "Hello World")

This passes the string "Hello World" as a parameter to your program as it is run through the shell.
theoriginalbit #3
Posted 25 July 2013 - 01:10 AM
Reading the MiscPeripherals' thread may also help, as you would find documentation which leads to this:


local p = peripheral.wrap("back")
p.speak("Hello World")

Also be aware that the speaker may not work on all Linux clients, and the Mac clients also have a bug at the moment too.

So knowing that the speaker peripheral has this function you can write a program to use this, using the read() function to gather input from the user.

function syntax

peripheralObj.speak( text, [optional] speed )
Xerxeth #4
Posted 25 July 2013 - 01:17 AM
I'm not familiar with the speaker peripheral, but in your shell.run call, try the following instead:


shell.run ("speaker", "Hello World")

This passes the string "Hello World" as a parameter to your program as it is run through the shell.

I have tried this before, and it will only execute the "speak" program. I forgot to mention that I've tried this. I'm about to try theoriginalbit's suggestion now though.
Xerxeth #5
Posted 25 July 2013 - 01:29 AM
Reading the MiscPeripherals' thread may also help, as you would find documentation which leads to this:


local p = peripheral.wrap("back")
p.speak("Hello World")

Also be aware that the speaker may not work on all Linux clients, and the Mac clients also have a bug at the moment too.

So knowing that the speaker peripheral has this function you can write a program to use this, using the read() function to gather input from the user.

function syntax

peripheralObj.speak( text, [optional] speed )

Thank you very much. I failed to spot what you found on it.

So I whipped up a little test code using what you have provided:

local p = peripheral.wrap("back")
p.speak("Hello World")
textutils.slowPrint("Hello World.")
And it works beautifully! I will be working on some programs that use this, and maybe even an Adventure map. Having a terminal talk back to you is pretty neat.

Thank you for the replies you two! :D/>