vbc.tgz and dD.c == voptions.c enclosed.
- From: Gary Kline <kline thought org>
- To: GTK Devel List <gtk-app-devel-list gnome org>
- Cc: gabriele greco dartseng it
- Subject: vbc.tgz and dD.c == voptions.c enclosed.
- Date: Mon, 23 Jul 2012 10:36:57 -0700
Folks,
Attached in my vbc.tgz tarball; this is my working VBC
program. As-is, it works/installs only with /home/kline/.VBC;
then runs when you type make. make builds ./vbc.
Typing /home/kline/.VBC/vbc brings up the application.
Mouse-clicking on the second of the three lower buttons,
"Run Text-To-Speech" invokes gvim and espeak.
As-is, VBC would only with a male voice and the voice
options. Below, is the file I need help integration
into the top menu bar "Options". This lets the speech-
impaired user the choice of changing gender and several
other espeak options. This is where I get into trouble.
Lines +433-437 or so below explain part of my problems.
I think I have taken this project about as far as I can
without some assistance. I need help from the
gnome-accessibility group as I work to modify and improve
this program for the disabled. Just that right *now* I'm
hoping this list can help me with the voice options code.
thanks much,
gary
--
Gary Kline kline thought org http://www.thought.org Public Service Unix
Voice By Computer (for Universal Access): http:/www.thought.org/vbc
Twenty-six years of service to the Unix community.
/*
gcc -Wall -Wextra -g voptions.c -o xV `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
*/
/* from here make this into:: Options callback */
#include <gtk/gtk.h>
#include <string.h>
#include <stdlib.h> // for exit()
#define PITCH 17.0
#define SPEED 100.0
#define VOLUME 100.0
#define DELAY 3.0
enum
{
MALE,
FEMALE
};
#define CONFIG "/tmp/chatConfig"
/* globals */
GtkWidget *gender_radio_male;
GtkWidget *gender_radio_female;
GtkWidget *pitch_scale1;
GtkWidget *speedWPM_scale2;
GtkWidget *volume_scale3;
GtkWidget *delay_scale4;
int valueGender = MALE; // default
double valuePitch, valueSpeed, valueVolume, valueDelay;
/* end globals */
/*
main prog writes default; this fn read and asks if ok
*/
void data_inout();
FILE *ifp, *ofp; /* in and out FILE pointers for fopen */
#define FALSE (0)
#define TRUE (~0)
static void
cb_gender_toggled (GtkToggleButton *button, gpointer userdata)
{
int malefemale = (int)userdata;
if (gtk_toggle_button_get_active (button))
{
if (malefemale == MALE)
{
fprintf(stdout, "Male \n");
}
else if (malefemale == FEMALE)
{
fprintf(stdout, "Female \n");
}
}
valueGender = malefemale;
fprintf(stderr,"valueGender: %d\n",valueGender);
}
static void hscale_value_changed_pitch (GtkRange *hscale, GtkWindow *parentWindow)
{
valuePitch = gtk_range_get_value(hscale);
//fprintf(stderr,"hscale pitch value: %g\n",valuePitch);
if (valueGender == 0)
{
fprintf(stdout, "\ngender is Male\n");
}
else
{
fprintf(stdout, "\ngender is Female\n");
}
fprintf(stdout,"In _pitch_: patch = %g, speed = %g, volume = %g delay = %g\n",
valuePitch, valueSpeed, valueVolume, valueDelay);
}
static void hscale_value_changed_speed (GtkRange *hscale, GtkWindow *parentWindow)
{
valueSpeed = gtk_range_get_value(hscale);
fprintf(stderr,"hscale speed value: %g\n",valueSpeed);
}
static void hscale_value_changed_volume (GtkRange *hscale, GtkWindow *parentWindow)
{
valueVolume = gtk_range_get_value(hscale);
fprintf(stderr,"hscale volume value: %g\n",valueVolume);
}
static void hscale_value_changed_delay (GtkRange *hscale, GtkWindow *parentWindow)
{
valueDelay = gtk_range_get_value(hscale);
fprintf(stderr,"hscale delay value: %g\n",valueDelay);
}
int
main (int argc, char *argv[])
{
/*
* Declare the GTK Widgets used in the program
*/
GtkWidget *dialog;
GtkWidget *main_hbox; //hbox1
GtkWidget *gender_frame;
GtkWidget *gender_align;
GtkWidget *gender_hbox; // hbox2
GtkWidget *params_frame;
GtkWidget *params_align;
GtkWidget *params_table;
GtkWidget *temp_widget;
GtkWidget *parent_window;
/*
Initialize GTK
*/
gtk_init (&argc, &argv);
parent_window = NULL; //Set to parent window if you want the dialog box
//to block access to the other windows in the app
//while it is open and running.
dialog = gtk_dialog_new_with_buttons ("Voice Settings", GTK_WINDOW (parent_window),
0,
GTK_STOCK_REVERT_TO_SAVED, //revert button which
GTK_RESPONSE_CANCEL, // returns a cancel response
GTK_STOCK_CLOSE, //close button which
GTK_RESPONSE_ACCEPT, // returns an accept response
NULL // mark the end of our buttons (we could have more)
);
gtk_window_set_title ( GTK_WINDOW ( dialog ) , "VBC Espeak Options");
gtk_widget_set_usize( GTK_WIDGET ( dialog ) , 600 , 400 );
//GTK_WINDOW ( dialog ) ->allow_shrink = TRUE;
/*
* dialog boxes have a vbox built in we can use
*/
main_hbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
/*
* Create the first frame
*/
gender_frame = gtk_frame_new ("<b>Voice Gender</b>");
gtk_frame_set_shadow_type (GTK_FRAME (gender_frame), GTK_SHADOW_NONE);
g_object_set (gtk_frame_get_label_widget (GTK_FRAME (gender_frame)),
"use-markup", TRUE, NULL);
gtk_widget_show (gender_frame);
/*
* ADD FRAME to the hbox
*/
gtk_box_pack_start (GTK_BOX (main_hbox), gender_frame, FALSE, FALSE, 0);//HBOX
/*
* Create an alignment widget to indent our child objects
*/
/*
* left aligned, top-aligned, children should fill the box
*/
gender_align = gtk_alignment_new (0, 0, 0, 1);
/*
* set a left margin of 12 pixels :: Padding
*/
gtk_alignment_set_padding (GTK_ALIGNMENT (gender_align), 0, 0, 12, 0);
gtk_widget_show (gender_align);
/*
* add alignmnet widget to frame
*/
gtk_container_add (GTK_CONTAINER (gender_frame), gender_align);
/*
* Create a [vh]box for the radio buttons and add it to the
* alignment widget inside the frame
*/
gender_hbox = gtk_hbox_new (FALSE, 2); //2 pixels between objects
gtk_widget_show (gender_hbox);
gtk_container_add (GTK_CONTAINER (gender_align), gender_hbox);
/*
* Create the first radio toggle-box with a label
*/
gender_radio_male = gtk_radio_button_new_with_label (NULL, "Male");
g_signal_connect (gender_radio_male,"toggled", G_CALLBACK (cb_gender_toggled),
(gpointer)MALE);
gtk_widget_show (gender_radio_male);
/*
* Create the rest of the radio toggle-box with label â??
*/
gender_radio_female = gtk_radio_button_new_with_label (gtk_radio_button_group
(GTK_RADIO_BUTTON (gender_radio_male)), "Female");
g_signal_connect (gender_radio_female, "toggled", G_CALLBACK (cb_gender_toggled),
(gpointer)FEMALE);
gtk_widget_show (gender_radio_female);
/*
* Pack the two radio buttons into the hbox.
*/
gtk_box_pack_start (GTK_BOX (gender_hbox), gender_radio_male, TRUE, TRUE, 2);
gtk_box_pack_start (GTK_BOX (gender_hbox), gender_radio_female, TRUE, TRUE, 2);
/************************************************************************************
End of male/female toggles
************************************************************************************/
/*
* Create the second frame
*/
params_frame = gtk_frame_new ("<b>Voice Parameters</b>");
gtk_frame_set_shadow_type (GTK_FRAME (params_frame), GTK_SHADOW_NONE);
g_object_set (gtk_frame_get_label_widget (GTK_FRAME (params_frame)),
"use-markup", TRUE, NULL);
gtk_widget_show (params_frame);
/*
* Add frame to the vbox [][]
*/
gtk_box_pack_start (GTK_BOX (main_hbox), params_frame, FALSE, FALSE, 0);
/*
* Create an alignment widget to indent our child objects
*
*
* left aligned, top-aligned, children should fill the box
*/
params_align = gtk_alignment_new (0, 0, 1, 1);
/*
* set a left margin of 12 pixels
*/
gtk_alignment_set_padding (GTK_ALIGNMENT (params_align), 0, 0, 12, 0);
gtk_widget_show (params_align);
/*
* add alignmnet widget to frame
*/
gtk_container_add (GTK_CONTAINER (params_frame), params_align);
/*
* create a table for the radio buttons and add it to the
* alignment widget inside the frame
*/
params_table = gtk_table_new (2, 2, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (params_table), 2);
gtk_table_set_col_spacings (GTK_TABLE (params_table), 7);
gtk_widget_show (params_table);
gtk_container_add (GTK_CONTAINER (params_align), params_table);
temp_widget = gtk_label_new ("Pitch");
/*
* push label left instead of centering
*/
gtk_misc_set_alignment (GTK_MISC (temp_widget), 0.0, 0.5);
gtk_widget_show (temp_widget);
gtk_table_attach (GTK_TABLE (params_table), temp_widget, 0, 1, //column 0 (first)
0, 1, //row 1 (second)
GTK_FILL, 0, // Don't grow in size on screen
0, 0);
temp_widget = gtk_label_new ("Speed WPM");
gtk_misc_set_alignment (GTK_MISC (temp_widget), 0.0, 0.5);//Push label left don't center
gtk_widget_show (temp_widget);
gtk_table_attach (GTK_TABLE (params_table), temp_widget, 0, 1, //Column 0 (first)
1, 2, //row 1 (second)
GTK_FILL, 0, //don't grow in size
0, 0);
temp_widget = gtk_label_new ("Volume");
gtk_misc_set_alignment (GTK_MISC (temp_widget), 0.0, 0.5);
gtk_widget_show (temp_widget);
gtk_table_attach (GTK_TABLE (params_table), temp_widget, 0, 1, //Column 0 (first)
2, 3, //row 2 (second)
GTK_FILL, 0,
0, 0);
temp_widget = gtk_label_new ("Delay");
gtk_misc_set_alignment (GTK_MISC (temp_widget), 0.0, 0.5); //push label left
gtk_widget_show (temp_widget);
gtk_table_attach (GTK_TABLE (params_table), temp_widget, 0, 1, //column 0 (first)
3, 4, //row 3 (third)
GTK_FILL, 0, //don't grow in size on screen
0, 0);
/**********
Set ranges
*********/
pitch_scale1 = gtk_hscale_new_with_range (0.0, 100.0, 1.0);
gtk_range_set_value(GTK_RANGE(pitch_scale1), 17.0);
gtk_widget_show (pitch_scale1);
gtk_table_attach (GTK_TABLE (params_table), pitch_scale1, 1, 2,
0, 1, //row 0 (first)
GTK_EXPAND | GTK_FILL, //this part expands when window grows
0, 0, 0);
g_signal_connect (G_OBJECT (pitch_scale1), "value_changed",
GTK_SIGNAL_FUNC (hscale_value_changed_pitch), (gpointer) parent_window);
valuePitch = PITCH;
speedWPM_scale2 = gtk_hscale_new_with_range (80.0, 390.0, 1.0);
gtk_range_set_value(GTK_RANGE(speedWPM_scale2), 150.0);
gtk_widget_show (speedWPM_scale2);
gtk_table_attach (GTK_TABLE (params_table), speedWPM_scale2, 1, 2, //column 1 (second)
1, 2, //row 0 (first)
GTK_EXPAND | GTK_FILL, //this part expands when window grows
0, 0, 0);
g_signal_connect (G_OBJECT (speedWPM_scale2), "value_changed",
GTK_SIGNAL_FUNC (hscale_value_changed_speed), (gpointer) parent_window);
valueSpeed = SPEED;
volume_scale3 = gtk_hscale_new_with_range (0.0, 200.0, 1.0);
gtk_range_set_value(GTK_RANGE(volume_scale3), 100.0);
gtk_widget_show (volume_scale3);
gtk_table_attach (GTK_TABLE (params_table), volume_scale3, 1, 2, //column 1 (second)
2, 3, //row 0 (first) MOD: 14:1
GTK_EXPAND | GTK_FILL, //this part expands when window grows
0, 0, 0);
g_signal_connect (G_OBJECT (volume_scale3), "value_changed",
GTK_SIGNAL_FUNC (hscale_value_changed_volume), (gpointer) parent_window);
valueVolume = VOLUME;
/*
* The "delay" is in 10ths of a second between words. The faster the words
* are spoken, the more sense it makes to allow for more delay between
* words. For a slow WPM delivery, 3 to 5 tenths should be plenty for
* DEFAULT.
*/
delay_scale4 = gtk_hscale_new_with_range (0.0, 100.0, 1.0);
gtk_range_set_value(GTK_RANGE(delay_scale4), 3.0);
gtk_widget_show (delay_scale4);
gtk_table_attach (GTK_TABLE (params_table), delay_scale4, 1, 2, //column 1 (second)
3, 4, //row 0 (first) MOD: 14:1
GTK_EXPAND | GTK_FILL, //this part expands when window grows
0, 0, 0);
g_signal_connect (G_OBJECT (delay_scale4), "value_changed",
GTK_SIGNAL_FUNC (hscale_value_changed_delay), (gpointer) parent_window);
valueDelay = DELAY;
/*****
Print gender, pitch, speed, volume, delay to stdout.
*****/
puts("Initially:\n");
if (valueGender == 0)
{
fprintf(stdout, "gender is Male\n");
}
else
{
fprintf(stdout, "gender is Female\n");
}
fprintf(stdout,"patch = %g, speed = %g, volume = %g delay = %g\n",
valuePitch, valueSpeed, valueVolume, valueDelay);
/*
* Run the dialog (a main loop starts automatically)
*/
gtk_dialog_run (GTK_DIALOG (dialog));
/*
* Return 0 if exit is successful.
*/
data_inout();
return 0;
}
/*
* here, we first-time WRITE (fprintf) all ints or data with %g.
* ./dD 1 indicdate fscanf and printf to stdout and /tmp/file, ready to be
* read at next instantiation.
*/
void
data_inout()
{
char vbcintvalue[16];
int gender, pitch, speed, volume, delay;
puts("IN inout");
if ((ifp = fopen(CONFIG, "r+")) == NULL)
{
printf("Cannot open for reading: [%s]\n", CONFIG);
exit(1);
}
else
{
fscanf(ifp, "%d %d %d %d %d\n", &gender, &pitch, &speed, &volume,&delay);
printf("This okay?: %d %d %d %d %d\n", gender,pitch,speed,volume,delay);
}
fclose(ifp);
/*
* popup with "printf()" data. Ask if okay. Yes, No,
* Do not ask again. if user clicks yes, close popup, if No, open Opions
* menu, and if Do not ask again, set flag in CONFIG dir and
* close popup and open main VBC window.
*/
if ((ofp = fopen(CONFIG, "w+")) == NULL)
{
printf("Cannot open for writing: [%s]\n", CONFIG);
exit(1);
}
else
{
//sprintf(vbcintvalue, "%d", counter);
fprintf(stdout, "INOUT: Gender is %d %g %g %g %g\n ", valueGender, valuePitch,
valueSpeed, valueVolume, valueDelay);
fprintf(ofp, "%d %g %g %g %g\n", valueGender, valuePitch, valueSpeed ,
valueVolume, valueDelay);
}
fclose(ofp);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]