File: pho-play.cpp

package info (click to toggle)
gcin 2.9.4%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,812 kB
  • sloc: cpp: 34,326; ansic: 9,319; makefile: 648; sh: 556
file content (141 lines) | stat: -rw-r--r-- 2,907 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "gcin.h"
#include "pho.h"
extern gboolean test_mode;
void load_tab_pho_file();

#if UNIX
#include <signal.h>
gboolean test_mode;

int pho_play(phokey_t key)
{
  if (!phonetic_speak)
    return 0;

  static char ogg123[]="/usr/bin/ogg123";
  if (access(ogg123, R_OK)) {
    box_warn("gcin speech needs 'ogg123' in 'vorbis-tools'");
    exit(1);
  }

  if (access(GCIN_OGG_DIR, R_OK)) {
	box_warn("You have to install the speech data:'ogg.tgz'");
    exit(1);
  }

  static int pid;
  static time_t last_time;
  time_t t = time(NULL);
  if (!gcin_sound_play_overlap) {
    if (pid && t - last_time < 2)
      kill(pid, 9);
  }
  char *ph = phokey_to_str2(key, 1);

  static char tt[128];
  sprintf(tt, GCIN_OGG_DIR"/%s/%s", ph, phonetic_speak_sel);
  last_time = t;

  if (pid = fork()) {
    if (pid < 0)
      dbg("cannot fork ?");
    return 1;
  }

#if 0
  close(1);
  close(2);
#endif

  execl(ogg123, "ogg123", tt, NULL);
  exit(1);
}
#else
extern "C" {
	HANDLE play_ogg_file(wchar_t *file_name);
};

void ErrorExit(LPTSTR lpszFunction);
void pho_play(phokey_t key)
{
  if (!phonetic_speak || test_mode)
    return;

#if 0
  static PROCESS_INFORMATION procinfo;
  static time_t last_time;
  time_t t = time(NULL);
#if 0
  // the result is bad on windows
  if (!gcin_sound_play_overlap) {
    if (procinfo.hProcess && t - last_time < 2)
      TerminateProcess(procinfo.hProcess, 0);
  }
#endif
  char *ph = phokey_to_str2(key, 1);
  char tt[512];

  last_time = t;
  if (procinfo.hProcess) {
    CloseHandle(procinfo.hProcess);
    CloseHandle(procinfo.hThread);
  }

  sprintf(tt, "\"%s\\bin\\oggdec.exe\" -p \"%s\\ogg\\%s\\%s\"", gcin_program_files_path, gcin_program_files_path, ph, phonetic_speak_sel);
  wchar_t tt16[MAX_PATH*2];

  utf8_to_16(tt, tt16, sizeof(tt16));
#if 0
  char pro[64];
  wchar_t pro16[64];
  strcpy(pro, gcin_program_files_path);
  strcat(pro, "\\oggdec.exe");
  utf8_to_16(pro, pro16, ARRAYSIZE(tt16));
#endif
  STARTUPINFOW si;
//  PROCESS_INFORMATION pi;

  ZeroMemory( &si, sizeof(si) );
  si.cb = sizeof(si);
  ZeroMemory( &procinfo, sizeof(procinfo));

  if(!CreateProcessW(NULL, tt16, NULL,NULL,FALSE, CREATE_NO_WINDOW, NULL,NULL, &si, &procinfo)) {
#if _DEBUG
    ErrorExit("CreateProcessW");
    dbg("cannot exec %s\n", tt);
#endif
  }
#else
  char *ph = phokey_to_str2(key, 1);
  char tt[512];
  sprintf(tt, "%s\\ogg\\%s\\%s", gcin_program_files_path, ph, phonetic_speak_sel);
  wchar_t tt16[MAX_PATH];
  utf8_to_16(tt, tt16, ARRAYSIZE(tt16));
  play_ogg_file(tt16);
#endif
}
#endif

void char_play(char *utf8)
{
  dbg("char_play %s\n", utf8);
  if (!phonetic_speak || !(utf8[0]&128))
    return;

  if (!ch_pho)
    load_tab_pho_file();

  phokey_t phos[16];
  int phosN = utf8_pho_keys((char *)utf8, phos);
  dbg("phosN:%d\n");
  if (!phosN)
    return;

#if 0
  int i;
  for(i=0; i < phosN; i++)
    pho_play(phos[i]);
#else
  pho_play(phos[0]);
#endif
}