5 #include <unistd.h> /* F_OK ?? */
17 #include "Pitch_to_Sound.h"
21 gpointer
sound_init(void *args
)
23 Sound melderSoundFromMic
;
26 gchar
*argv
[2] = { "Praat", "niets" };
27 praat_init("Praat", 2, argv
);
32 gsl_set_error_handler_off ();
33 Melder_setMaximumAsynchronicity (Melder_SYNCHRONOUS
);
35 melderSoundFromMic
= Sound_recordFixedTime (1, 1.0, 0.5, 44100, 1.0);
36 forget(melderSoundFromMic
);
37 // Melder_clearError();
38 Melder_flushError (NULL
);
42 static void playInPraat(gchar
*path
) {
43 if (g_access(path
, F_OK
) == 0) {
44 structMelderFile file
;
45 Sound melderSoundFromFile
;
46 Melder_pathToFile(path
, & file
);
47 melderSoundFromFile
= Sound_readFromSoundFile (& file
);
48 if (! melderSoundFromFile
) {
49 g_warning(_("Praat cannot open the file!"));
51 Sound_play(melderSoundFromFile
, NULL
, NULL
);
52 forget(melderSoundFromFile
);
55 g_warning(_("The file %s just doesn't exist!"), path
);
58 // Melder_flushError (NULL);
62 static void playVoice() {
66 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
67 path
= voicepath(string
);
75 static void playHum() {
78 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
80 gchar
*upper
= g_malloc(4);
81 g_ascii_dtostr(upper
, 4, upperRegister
);
83 path
= g_strjoin(NULL
, PITCHPATH
, G_DIR_SEPARATOR_S
, string
, "-", upper
, ".wav", NULL
);
85 path
= g_strjoin(NULL
, PITCHPATH
, G_DIR_SEPARATOR_S
, string
, "-", upper
, ".Pitch", NULL
);
92 if (g_access(path
, F_OK
) == 0) {
93 structMelderFile file
;
94 Pitch melderPitchFromFile
;
96 __declspec(dllimport
) Pitch_Table classPitch
;
98 Thing_recognizeClassesByName (classPitch
, NULL
);
99 Melder_pathToFile(path
, & file
);
100 melderPitchFromFile
= Data_readFromTextFile (& file
);
101 if (melderPitchFromFile
!= NULL
) {
102 Pitch_hum(melderPitchFromFile
, 0, 0);
103 forget(melderPitchFromFile
);
105 // g_debug("PITCH IS NULL!");
116 static void playBefore() {
117 GtkWidget
*gimiVoice
= glade_xml_get_widget(xml
, "checkmenuitemBeforeVoice");
118 GtkWidget
*gimiHum
= glade_xml_get_widget(xml
, "checkmenuitemBeforeHum");
120 /* Check play Example */
121 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiVoice
))) {
127 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiHum
))) {
132 gpointer
example(void *args
) {
133 GtkWidget
*gimiVoice
= glade_xml_get_widget(xml
, "checkmenuitemExampleVoice");
134 GtkWidget
*gimiHum
= glade_xml_get_widget(xml
, "checkmenuitemExampleHum");
136 g_idle_add(setButtonsFalse
, NULL
);
138 /* Check play Example */
139 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiVoice
))) {
145 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiHum
))) {
149 g_idle_add(setButtonsTrue
, NULL
);
153 gpointer
play(void *args
) {
155 gchar
*path
= pathToPlay();
156 g_idle_add(setButtonsFalse
, NULL
);
161 g_idle_add(setButtonsTrue
, NULL
);
166 gpointer
record(void *args
) {
169 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
170 // g_debug("%s %d welcome!\n\n\n", __func__, rand());
171 g_idle_add(setButtonsFalse
, NULL
);
173 if (g_access(RECORDPATH
, F_OK
) == 0) {
174 Sound melderSoundFromMic
= Sound_recordFixedTime (1, 1.0, 0.5, 44100, RECORDTIME
);
176 if (! melderSoundFromMic
) {
177 g_warning(_("No sound from praat!"));
179 GString
*filename
= g_string_sized_new(128);
180 GString
*cmd
= g_string_sized_new(128);
182 structMelderFile file
;
184 g_string_printf(filename
, "%s.wav", string
);
186 path
= g_build_filename(RECORDPATH
, filename
->str
, NULL
);
187 g_string_free(filename
, TRUE
);
189 Vector_scale(melderSoundFromMic
, 0.99);
190 Melder_pathToFile(path
, &file
);
191 Sound_writeToAudioFile16 (melderSoundFromMic
, &file
, Melder_WAV
);
192 forget(melderSoundFromMic
);
197 g_string_printf(cmd
, "%s SGC_ToneProt.praat ..%s%s %s %0.f 3 none 0", PRAATBIN
, G_DIR_SEPARATOR_S
, path
, string
, upperRegister
);
198 // g_debug(cmd->str);
199 // g_debug("EXECUTES! ");
201 // g_debug("DONE!\n");
204 g_string_printf(cmd
, "SGC_ToneProt.praat ..%s%s %s %0.f 3 none 0", G_DIR_SEPARATOR_S
, path
, string
, upperRegister
);
205 praat_executeScriptFromFileNameWithArguments(cmd
->str
);
211 g_string_free(cmd
, TRUE
);
214 g_warning(_("Missing recording directory %s."), RECORDPATH
);
218 // Melder_flushError (NULL);
219 g_idle_add(setButtonsTrue
, NULL
);
220 // g_debug("%s bye!\n", __func__);