1 #include "singleword.h"
13 #include "Pitch_to_Sound.h"
16 gboolean
setButtonsTrue() {
20 gboolean setButton
= TRUE
;
21 GtkWidget
*buttonRecord
= glade_xml_get_widget(xml
, "buttonRecord");
22 GtkWidget
*buttonPlay
= glade_xml_get_widget(xml
, "buttonPlay");
23 GtkWidget
*buttonHum
= glade_xml_get_widget(xml
, "buttonHum");
24 GtkWidget
*drawingareaPitch
= glade_xml_get_widget(xml
, "drawingareaPitch");
25 gchar
*path
= g_build_filename(RECORDPATH
, "singleword.wav", NULL
);
26 if (g_access(path
, F_OK
) == -1) setButton
= FALSE
;
28 gtk_widget_set_sensitive(buttonPlay
, setButton
);
29 gtk_widget_set_sensitive(buttonRecord
, TRUE
);
30 gtk_widget_set_sensitive(buttonHum
, TRUE
);
33 gtk_widget_queue_draw(drawingareaPitch
);
35 feedbackTXT
= g_build_filename(SCRIPTPATH
, G_DIR_SEPARATOR_S
, "feedback.txt", NULL
);
37 if (g_file_get_contents(feedbackTXT
, &contents
, NULL
, NULL
) == TRUE
) {
38 GtkWidget
*label
= glade_xml_get_widget(xml
, "labelFeedback");
39 gtk_label_set_text(GTK_LABEL(label
), contents
);
40 g_unlink(feedbackTXT
);
47 gboolean
setButtonsFalse() {
48 GtkWidget
*buttonRecord
= glade_xml_get_widget(xml
, "buttonRecord");
49 GtkWidget
*buttonPlay
= glade_xml_get_widget(xml
, "buttonPlay");
50 GtkWidget
*buttonHum
= glade_xml_get_widget(xml
, "buttonHum");
52 gtk_widget_set_sensitive(buttonRecord
, FALSE
);
53 gtk_widget_set_sensitive(buttonPlay
, FALSE
);
54 gtk_widget_set_sensitive(buttonHum
, FALSE
);
58 gpointer
sound_init(void *args
)
60 Sound melderSoundFromMic
;
62 gchar
*argv
[2] = { "Praat", "niets" };
63 praat_init("Praat", 2, argv
);
67 Melder_setMaximumAsynchronicity (Melder_SYNCHRONOUS
);
69 melderSoundFromMic
= Sound_recordFixedTime (1, 1.0, 0.5, 44100, 1.0);
70 forget(melderSoundFromMic
);
72 g_idle_add(setButtonsTrue
, NULL
);
76 static void playInPraat(gchar
*path
) {
77 if (g_access(path
, F_OK
) == 0) {
78 structMelderFile file
;
79 Sound melderSoundFromFile
;
80 Melder_pathToFile(path
, & file
);
81 melderSoundFromFile
= Sound_readFromSoundFile (& file
);
82 if (! melderSoundFromFile
) {
83 g_warning(_("Praat cannot open the file!"));
85 Sound_play(melderSoundFromFile
, NULL
, NULL
);
86 forget(melderSoundFromFile
);
89 g_warning(_("The file %s just doesn't exist!"), path
);
94 gpointer
playHum(void *args
) {
96 GString
*filename
= g_string_sized_new (200);
97 g_string_printf(filename
, "%s%s%s-%0.f.wav", PITCHPATH
, G_DIR_SEPARATOR_S
, active
, upperRegister
);
98 g_idle_add(setButtonsFalse
, NULL
);
99 playInPraat(filename
->str
);
100 g_string_free(filename
, TRUE
);
101 g_idle_add(setButtonsTrue
, NULL
);
107 gpointer
play(void *args
) {
108 gchar
*path
= g_build_filename(RECORDPATH
, "singleword.wav", NULL
);
109 g_idle_add(setButtonsFalse
, NULL
);
112 g_idle_add(setButtonsTrue
, NULL
);
116 gpointer
record(void *args
) {
117 if (active
!= NULL
) {
118 g_idle_add(setButtonsFalse
, NULL
);
119 if (g_access(RECORDPATH
, F_OK
) == 0) {
120 Sound melderSoundFromMic
= Sound_recordFixedTime (1, 1.0, 0.5, 44100, RECORDTIME
);
121 if (! melderSoundFromMic
) {
122 g_warning(_("No sound from praat!"));
124 GString
*cmd
= g_string_sized_new(128);
126 structMelderFile file
;
128 path
= g_build_filename(RECORDPATH
, "singleword.wav", NULL
);
131 Vector_scale(melderSoundFromMic
, 0.99);
132 Melder_pathToFile(path
, &file
);
133 Sound_writeToAudioFile16 (melderSoundFromMic
, &file
, Melder_WAV
);
134 forget(melderSoundFromMic
);
138 g_string_printf(cmd
, "%s SGC_ToneProt.praat ..%s%s %s %0.f 3 none 0", PRAATBIN
, G_DIR_SEPARATOR_S
, path
, active
, upperRegister
);
141 g_string_printf(cmd
, "SGC_ToneProt.praat ..%s%s %s %0.f 3 none 0", G_DIR_SEPARATOR_S
, path
, active
, upperRegister
);
142 praat_executeScriptFromFileNameWithArguments(cmd
->str
);
148 g_string_free(cmd
, TRUE
);
151 g_warning(_("Missing recording directory %s."), RECORDPATH
);
154 g_idle_add(setButtonsTrue
, NULL
);