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
);
43 static void playInPraat(gchar
*path
) {
44 if (g_access(path
, F_OK
) == 0) {
45 structMelderFile file
;
46 Sound melderSoundFromFile
;
47 Melder_pathToFile(Melder_peekUtf8ToWcs(path
), & file
);
48 melderSoundFromFile
= Sound_readFromSoundFile (& file
);
49 if (! melderSoundFromFile
) {
50 g_warning(_("Praat cannot open the file!"));
52 Sound_play(melderSoundFromFile
, NULL
, NULL
);
53 forget(melderSoundFromFile
);
56 g_warning(_("The file %s just doesn't exist!"), path
);
59 // Melder_flushError (NULL);
63 static void playVoice() {
67 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
68 path
= voicepath(string
);
76 static void playHum() {
79 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
81 gchar
*upper
= g_malloc(4);
82 g_ascii_dtostr(upper
, 4, upperRegister
);
84 path
= g_strjoin(NULL
, PITCHPATH
, G_DIR_SEPARATOR_S
, string
, "-", upper
, ".wav", NULL
);
86 path
= g_strjoin(NULL
, PITCHPATH
, G_DIR_SEPARATOR_S
, string
, "-", upper
, ".Pitch", NULL
);
93 if (g_access(path
, F_OK
) == 0) {
94 structMelderFile file
;
95 Pitch melderPitchFromFile
;
97 __declspec(dllimport
) Pitch_Table classPitch
;
99 Thing_recognizeClassesByName (classPitch
, NULL
);
100 Melder_pathToFile(Melder_peekUtf8ToWcs(path
), & file
);
101 melderPitchFromFile
= Data_readFromTextFile (& file
);
102 if (melderPitchFromFile
!= NULL
) {
103 Pitch_hum(melderPitchFromFile
, 0, 0);
104 forget(melderPitchFromFile
);
106 // g_debug("PITCH IS NULL!");
117 static void playBefore() {
118 GtkWidget
*gimiVoice
= glade_xml_get_widget(xml
, "checkmenuitemBeforeVoice");
119 GtkWidget
*gimiHum
= glade_xml_get_widget(xml
, "checkmenuitemBeforeHum");
121 /* Check play Example */
122 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiVoice
))) {
128 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiHum
))) {
133 gpointer
example(void *args
) {
134 GtkWidget
*gimiVoice
= glade_xml_get_widget(xml
, "checkmenuitemExampleVoice");
135 GtkWidget
*gimiHum
= glade_xml_get_widget(xml
, "checkmenuitemExampleHum");
137 g_idle_add(setButtonsFalse
, NULL
);
139 /* Check play Example */
140 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiVoice
))) {
146 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiHum
))) {
150 g_idle_add(setButtonsTrue
, NULL
);
155 gpointer
play(void *args
) {
157 gchar
*path
= pathToPlay();
158 g_idle_add(setButtonsFalse
, NULL
);
163 g_idle_add(setButtonsTrue
, NULL
);
169 gpointer
record(void *args
) {
172 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
173 // g_debug("%s %d welcome!\n\n\n", __func__, rand());
174 g_idle_add(setButtonsFalse
, NULL
);
176 if (g_access(RECORDPATH
, F_OK
) == 0) {
177 Sound melderSoundFromMic
= Sound_recordFixedTime (1, 1.0, 0.5, 44100, RECORDTIME
);
179 if (! melderSoundFromMic
) {
180 g_warning(_("No sound from praat!"));
182 GString
*filename
= g_string_sized_new(128);
183 GString
*cmd
= g_string_sized_new(128);
185 structMelderFile file
;
187 g_string_printf(filename
, "%s.wav", string
);
189 path
= g_build_filename(RECORDPATH
, filename
->str
, NULL
);
190 g_string_free(filename
, TRUE
);
192 Vector_scale(melderSoundFromMic
, 0.99);
193 Melder_pathToFile(Melder_peekUtf8ToWcs(path
), &file
);
194 Sound_writeToAudioFile16 (melderSoundFromMic
, &file
, Melder_WAV
);
195 forget(melderSoundFromMic
);
200 g_string_printf(cmd
, "%s SGC_ToneProt.praat ..%s%s %s %0.f 3 none 0", PRAATBIN
, G_DIR_SEPARATOR_S
, path
, string
, upperRegister
);
201 // g_debug(cmd->str);
202 // g_debug("EXECUTES! ");
204 // g_debug("DONE!\n");
207 g_string_printf(cmd
, "SGC_ToneProt.praat ..%s%s %s %0.f 3 none 0", G_DIR_SEPARATOR_S
, path
, string
, upperRegister
);
208 praat_executeScriptFromFileNameWithArguments(cmd
->str
);
214 g_string_free(cmd
, TRUE
);
217 g_warning(_("Missing recording directory %s."), RECORDPATH
);
221 // Melder_flushError (NULL);
222 g_idle_add(setButtonsTrue
, NULL
);
223 // g_debug("%s bye!\n", __func__);