2 #include <unistd.h> /* F_OK ?? */
14 #include "Pitch_to_Sound.h"
18 gpointer
sound_init(void *args
)
20 Sound melderSoundFromMic
;
23 gsl_set_error_handler_off ();
24 Melder_setMaximumAsynchronicity (Melder_SYNCHRONOUS
);
26 melderSoundFromMic
= Sound_recordFixedTime (1, 1.0, 0.5, 44100, 1.0);
27 forget(melderSoundFromMic
);
28 Melder_flushError (NULL
);
32 void playInPraat(gchar
*path
) {
33 if (g_access(path
, F_OK
) == 0) {
34 structMelderFile file
;
35 Sound melderSoundFromFile
;
36 Melder_pathToFile(path
, & file
);
37 melderSoundFromFile
= Sound_readFromSoundFile (& file
);
38 if (! melderSoundFromFile
) {
39 g_warning("Praat cannot open the file!\n");
41 Sound_play(melderSoundFromFile
, NULL
, NULL
);
42 forget(melderSoundFromFile
);
45 g_warning("The file %s just don't exist!\n", path
);
47 Melder_flushError (NULL
);
54 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
55 gchar
*path
= g_strjoin(NULL
, PINYINPATH
, G_DIR_SEPARATOR_S
, string
, ".wav", NULL
);
65 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
67 gchar
*upper
= g_malloc(4);
68 g_ascii_dtostr(upper
, 4, upperRegister
);
70 path
= g_strjoin(NULL
, PITCHPATH
, G_DIR_SEPARATOR_S
, string
, "-", upper
, ".wav", NULL
);
72 path
= g_strjoin(NULL
, PITCHPATH
, G_DIR_SEPARATOR_S
, string
, "-", upper
, ".Pitch", NULL
);
79 if (g_access(path
, F_OK
) == 0) {
80 structMelderFile file
;
81 Pitch melderPitchFromFile
;
83 __declspec(dllimport
) Pitch_Table classPitch
;
85 Thing_recognizeClassesByName (classPitch
, NULL
);
86 Melder_pathToFile(path
, & file
);
87 melderPitchFromFile
= Data_readFromTextFile (& file
);
88 if (melderPitchFromFile
!= NULL
) {
89 Pitch_hum(melderPitchFromFile
, 0, 0);
90 forget(melderPitchFromFile
);
92 g_debug("PITCH IS NULL!");
98 Melder_flushError (NULL
);
104 GtkWidget
*gimiChinese
= glade_xml_get_widget(xml
, "checkmenuitemBeforeVoice");
105 GtkWidget
*gimiHum
= glade_xml_get_widget(xml
, "checkmenuitemBeforeHum");
107 /* Check play Example */
108 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiChinese
))) {
114 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiHum
))) {
119 gpointer
example(void *args
) {
120 GtkWidget
*gimiChinese
= glade_xml_get_widget(xml
, "checkmenuitemExampleVoice");
121 GtkWidget
*gimiHum
= glade_xml_get_widget(xml
, "checkmenuitemExampleHum");
123 g_idle_add(setButtonsFalse
, NULL
);
125 /* Check play Example */
126 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiChinese
))) {
132 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiHum
))) {
136 g_idle_add(setButtonsTrue
, NULL
);
140 gpointer
play(void *args
) {
144 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
145 g_idle_add(setButtonsFalse
, NULL
);
146 path
= g_strjoin(NULL
, RECORDPATH
, G_DIR_SEPARATOR_S
, string
, ".wav", NULL
);
150 g_idle_add(setButtonsTrue
, NULL
);
156 gpointer
record(void *args
) {
159 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
160 g_debug("%s %d welcome!\n\n\n", __func__
, rand());
161 g_idle_add(setButtonsFalse
, NULL
);
163 if (g_access(RECORDPATH
, F_OK
) == 0) {
164 Sound melderSoundFromMic
= Sound_recordFixedTime (1, 1.0, 0.5, 44100, 5.0);
166 if (! melderSoundFromMic
) {
167 g_warning("No sound from praat!\n");
169 GString
*filename
= g_string_sized_new(128);
170 GString
*cmd
= g_string_sized_new(128);
172 structMelderFile file
;
174 g_string_printf(filename
, "%s.wav", string
);
176 path
= g_build_filename(RECORDPATH
, filename
->str
, NULL
);
177 g_string_free(filename
, TRUE
);
179 Vector_scale(melderSoundFromMic
, 0.99);
180 Melder_pathToFile(path
, &file
);
181 Sound_writeToAudioFile16 (melderSoundFromMic
, &file
, Melder_WAV
);
182 forget(melderSoundFromMic
);
185 g_string_printf(cmd
, "%s SGC_ToneProt.praat ..%s%s %s %0.f 3 none 0", PRAATBIN
, G_DIR_SEPARATOR_S
, path
, string
, upperRegister
);
188 g_debug("EXECUTES! ");
192 g_string_free(cmd
, TRUE
);
195 g_warning("Missing recording directory %s.", RECORDPATH
);
198 Melder_flushError (NULL
);
199 g_idle_add(setButtonsTrue
, NULL
);
200 g_debug("%s bye!\n", __func__
);