VoiceXML Prompt & SSML <mark> element. How to read prompt from the specified position? - vxml

<mark> element informs that reading went on to some point.
But is there a way we could read the prompt again from the specified position returned by mark (name) id?
It could be useful in such a scenario: we are reading a long text. Then the user commands: PAUSE.
We stop. Then the user would say "Go on". And we continue to read the prompt from the last position.
IS that possible at all?
And I would ask yet another question. No matter with the usage of SSML or not:
How to make it work - pause the prompt reading and then continue from the position where we stopped?
Pause means "take full control over that pause", so that we could continue whenever we wanted. Dynamically.

Mark is normally meant to be used at normal breakpoints. You may find it useful to place them at paragraph breaks or maybe at sentence breaks. As long as your application keeps track of where the mark ids are in your source text, you should be able to restart audio in that area.
Be aware that to implement mark, most platforms break the text and submit the pieces between mark entries to a rendering layer, then play the clip, one at a time. Therefore, you might see pauses as the platform crosses a mark.
It is also worth noting that only a subset of VoiceXML platforms implement mark so the availability of mark or differences in behavior could become an issue if you need to run on additional platforms.

Related

How to get current keyboard cursor position in Linux terminal

I am dealing with an issue in Ubuntu. I want to get current keyboard cursor position in terminal via Gcc
any assist...
"Terminal" is a program, or more accurately a description of a large class of programs, which implements a graphical interface emulating an external terminal (which would have been connected to your computer via a serial cable, or in some similar fashion). Your program communicates with the terminal emulator through a kind of bidirectional pipe (a "pseudoterminal") implemented by the operating system; to your program it looks like a pair of ordinary streams (stdin and stdout).
Linux itself has a terminal emulator, called "the console", which can be used instead of a window manager. Few programmers use it these days, but it's still there if you want to experiment. The console is a "terminal" (and there are usually several of them which you can switch between using a control+function key). As you might expect from the words "terminal" and "pseudoterminal", these basically look the same to your application.
There are a ton of details, which I'm skipping over because it would take a book to describe the whole thing.
The only connection between your program and the terminal (or pseudoterminal) is that you can send it a stream of characters, and you can receive a stream of characters from it. There is no other communication. There's no hidden operating system interface, because the terminal emulator is not part of the operating system. It's not even part of the window manager. It's just another userland application running without special privileges, just like your application.
You often want to do things other than just send characters to the output device. Maybe you want to clear the screen, or move the cursor to another location, or change the colour of the text or the background. All of these things are done by sending specially coded sequences interspersed with the text you're displaying. The operating system doesn't mediate or verify these sequences, and there's no definitive standard for how the terminal emulator should interpret them, but there is common framework which most terminal emulators conform to, to some extent, which makes it possible to actually write code which doesn't need to know exactly which terminal emulator is being used at the moment. The terminfo library is commonly used to describe the available terminals; by convention, the environment variable TERM contains the name of the relevant terminfo configuration, and that configuration can be used to create concrete control sequence strings suitable for the configured terminal [Note 1].
Now let's get back to your initial question: "how do I find out the current cursor location?" That's one of a small number of possible queries, which are also implemented as control sequences. Specifically, you send the terminal a control sequnce which asks it where the cursor is (usually the four characters \x1B[6n) and the terminal eventually replies with a control sequence which might look something like \x1B12,7R meaning that the cursor was on row 12 at column 7 at the moment that the control sequence was sent [Note 2]. So you could use terminfo to help you send the query and then attempt to parse the reply when it comes.
Note that the response is not synchronous with the query, since the user could be typing while the query is sent. (However, the response is sent as a contiguous sequence.) So part of the parsing process is disentangling the user input from the query response.
My guess is that you don't actually want to do all that work. In most cases, if you want to write a console application which does something less boring than just write output sequentially to a terminal window, you should use ncurses (also maintained by Thomas Dickey) or some other similar library. Ncurses takes full responsibility for maintaining the console image, jumping through the necessary hoops to communicate with the terminal emulator; one of its features is to keep track of the current cursor position [Note 3].
Another option, if you are only trying to provide better line editing and tab completion, is to use the GNU Readline library, or similar interfaces available for other operating systems.
Notes
This might or might not be the terminal you're actually using, since TERM is just an environment variable. You could set it yourself if you wanted it.
I took those codes from man 4 console_codes; another good source of information is Thomas Dickey's terse list of code sequences understood by xterm.
As far as I know, Ncurses does not use the cursor-position query to figure out where the cursor is on the screen. It maintains its own copy of the screen being displayed, which includes the current cursor position. You can use the macro getyx() to ask for what it considers the current cursor position.

How to write to input part in C?

I'm trying to write a mini shell in C for a school project, and what I want to do is doing a sort of command history (like in shell), when I press the UP key it writes the previous input into the input part, DOWN does the opposite, etc..., and you can edit it before pressing enter to send it to the program, like this (sorry for the bad english): [] represents the user cursor
my_shell$ some input wrote by me
my_shell$ []
my_shell$ some other input
my_shell$ []
and now if I press UP
my_shell$ some other input[]
If I press UP again
my_shell$ some input wrote by me[]
I'm allowed to use termcaps and some other functions isatty, ttyname, ttyslot, ioctl, getenv, tcsetattr, tcgetattr, tgetent, tgetflag, tgetnum, tgetstr, tgoto, tputs.
The problem is I can't understand the documentation of ioctl and tty functions, and I can't find well explained tutorials on these functions with examples, and I can't find the documentation for what I'm trying to do with them.
Can someone explain me those functions in an understandable way ? And how should I apply them for what I'm trying to do (I'm searching for a Linux-MacOs compatibility way)
Thanks for your help.
What you are asking is non trivial and will require a fair amount of work. Basically, what you need to do is use tcsetattr to put the terminal into non-canonical mode where the terminal's input line buffering is disabled and every keystroke will be returned immediately rather than waiting for a newline. You will then have to process every keystroke yourself, including backspace/delete and up/down arrows. Because of what you want to do with line editing, you'll probably also have to disable echoing and do the echo yourself.
You'll need to maintain the current line buffer yourself, and you'll also need a data structure that stores all the older lines of input (the history) and when an up-arrow is hit, you'll need to erase what you've currently buffered for the input, and erase it from the screen, then copy the history into your current buffer and echo it to the terminal.
Another complication is that keys like up-arraow and down-arrow are not part of ascii, so won't be read as a single byte -- instead they'll be multibyte escape sequences (likely beginning with an ESC ('\x1b') character). You can use tgetstr to quesry the terminal database to figure out what they are, or just hardcode your shell to use the ANSI sequences which are what almost all terminals you will see these days use.

easy way to get and print input onto window

I'm developing an app in C using ncurses, I want a box where I can get user input, only problem is, I can't find a way to do it that works the way I need it to.
For example, the closest ive come is the mvwgetnstr() routine, however this doesn't print the inputted characters back onto the window like I want it to. Ive searched around for quite a while now but I couldn't find anything.
Thanks for the help!
edit: just to clarify, I would need a routine like mvwgetnstr() just with the input being printed back onto the window.
The getstr manual page tells you:
Characters input are echoed only if echo is currently on. In that
case, backspace is echoed as deletion of the previous character (typically a left motion).
and the echo manual page gives you more information:
The echo and noecho routines control whether characters typed by the
user are echoed by getch(3x) as they are typed. Echoing by the tty
driver is always disabled, but initially getch is in echo mode, so
characters typed are echoed. Authors of most interactive programs prefer to do their own echoing in a controlled area of the screen, or not
to echo at all, so they disable echoing by calling noecho. [See
curs_getch(3x) for a discussion of how these routines interact with
cbreak and nocbreak.]
The ncurses manual page advised initializing it with noecho; your program can turn that off (or on), at any time.

How can I poll keyboard input in c?

I'm trying to make a simple game for the unix terminal, written in c. I've
been looking for a way to poll the keyboard, but haven't had any luck.
Currently I'm using ncurses getch() function. It works okay but if the user holds a key, the keyboard repeat will take a moment to start - also it will halt if any other key is pressed. This causes problems when playing (especially in two player mode where both games are controlled from a single input thread).
For example, if player 1 holds down 'a' and player 2 holds down 'b', I need to poll the keyboard and handle a stream of input like this:
abababababababab
As another example, if player 1 holds down the 'a' key and also presses the 'b' key, I need the input to be handled like this:
aaaaaaabaaaaaaaa
This way the simultaneous key presses don't interrupt each other. So I basically need to poll the keys on the keyboard on a set interval, and create my own implementation of a key press repeater.
Is there a way in c (with or without ncurses) to simply poll the keyboard on a time interval and read in all keys that are currently being pressed? From there I can just design the keyboard input thread to manage repeating actions manually. Basically something along the lines of kbhit, so I can check the status of a given key. But that will also let me poll the arrow keys.
It doesn't work that way:
Basically something along the lines of kbhit, so I can check the status of a given key. But that will also let me poll the arrow keys.
In any system that doesn't allow direct access to the hardware (MS-DOS is the only example you're likely to have encountered, others would include embedded systems), you're only able to read a sequence of characters (not keys) in a terminal application. GUI applications rely upon a server which does access some of the hardware (more) directly, but transforms the data.
In a terminal (such as used by ncurses), you can only check if the incoming characters includes the one that corresponds to the keyboard-key that you're interested in. Arrow keys send a sequence of characters: with ncurses you can either read the individual characters in the sequence, or rely upon ncurses to match the sequence to a known key in the terminal description.
Even with system-specific things such as the Linux console, you won't find much support for reading the keyboard as a whole: only character events. Read kbd_mode and console_ioctl to see what's available, keeping in mind this ancient caveat from the latter:
Warning: Do not regard this man page as documentation of the Linux
console ioctls. This is provided for the curious only, as an
alternative to reading the source. Ioctl's are undocumented Linux
internals, liable to be changed without warning. (And indeed, this
page more or less describes the situation as of kernel version
1.1.94; there are many minor and not-so-minor differences with
earlier versions.)
The suggested link Receiving key press and key release events in Linux terminal applications? gives some useful information. But as noted, the question (aside from the last point mentioned) is a duplicate.

How to get a character while inside a loop without stopping in the loop?

Hello I am new to C programming but I am making a menu for a game. I have a fish in ascii art displayed and it gets moved one character over every .5 secs. I accomplish this by a simple loop and it keeps on going across the screen then when it reaches the end, the fish is cleared and then it gets repeated again. Now while this animation is going on I would like to prompt the user for an input, however when I do that with getchar or scanf for example the fish loop waits until I press something and the animation stops until I press a key. Coould someone please shed some light on my problem??
Thank-you
You can't do this with any of the standard input methods. You're going to either have to use something like ncurses, or put the terminal into raw mode and do some pretty fancy manipulations. I have no idea what platform you're on, but raw mode is difficult under Linux, and even harder under Windows, so I'd stick with a library if you can.
Welcome to the world of Threads.
To understand threads think of how your computer works. If your computer ran without threads, you would not be able to run multiple applications at the same time. Threads allow for multiple parts of a program or interface to run at the same time without depending on eachother.
In your case, you will want a thread for the input and a separate thread for the animation. Thus allowing both to run separately.

Resources