-
Notifications
You must be signed in to change notification settings - Fork 0
/
xf_windows.go
706 lines (581 loc) · 21.9 KB
/
xf_windows.go
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
package xf
import (
"fmt"
"syscall"
"unsafe"
)
const (
MSP_SUCCESS = 0
)
func unsafeString(p string) unsafe.Pointer {
return unsafe.Pointer(&[]byte(p + "\x00")[0])
}
func uintptrToBytes(ptr uintptr, size int) []byte {
if ptr != 0 {
us := make([]byte, 0, size)
p := ptr
for i := 0; i < size; i++ {
u := *(*byte)(unsafe.Pointer(p + uintptr(i)))
us = append(us, u)
}
return us
}
return nil
}
func uintptrToString(cstr uintptr) string {
if cstr != 0 {
us := make([]byte, 0, 256*1024)
for p := cstr; ; p += 1 {
u := *(*byte)(unsafe.Pointer(p))
if u == 0 {
return string(us)
}
us = append(us, u)
}
}
return ""
}
var (
xunfei = syscall.NewLazyDLL("xunfei.dll")
procMSPDownloadData = xunfei.NewProc("xfMSPDownloadData")
procMSPGetParam = xunfei.NewProc("xfMSPGetParam")
procMSPGetVersion = xunfei.NewProc("xfMSPGetVersion")
procMSPLogin = xunfei.NewProc("xfMSPLogin")
procMSPLogout = xunfei.NewProc("xfMSPLogout")
procMSPNlpSchCancel = xunfei.NewProc("xfMSPNlpSchCancel")
procMSPNlpSearch = xunfei.NewProc("xfMSPNlpSearch")
procMSPRegisterNotify = xunfei.NewProc("xfMSPRegisterNotify")
procMSPSearch = xunfei.NewProc("xfMSPSearch")
procMSPSetParam = xunfei.NewProc("xfMSPSetParam")
procMSPUploadData = xunfei.NewProc("xfMSPUploadData")
procQISEAudioWrite = xunfei.NewProc("xfQISEAudioWrite")
procQISEGetParam = xunfei.NewProc("xfQISEGetParam")
procQISEGetResult = xunfei.NewProc("xfQISEGetResult")
procQISEResultInfo = xunfei.NewProc("xfQISEResultInfo")
procQISESessionBegin = xunfei.NewProc("xfQISESessionBegin")
procQISESessionEnd = xunfei.NewProc("xfQISESessionEnd")
procQISETextPut = xunfei.NewProc("xfQISETextPut")
procQISRAudioWrite = xunfei.NewProc("xfQISRAudioWrite")
procQISRBuildGrammar = xunfei.NewProc("xfQISRBuildGrammar")
procQISRGetBinaryResult = xunfei.NewProc("xfQISRGetBinaryResult")
procQISRGetParam = xunfei.NewProc("xfQISRGetParam")
procQISRGetResult = xunfei.NewProc("xfQISRGetResult")
procQISRSessionBegin = xunfei.NewProc("xfQISRSessionBegin")
procQISRSessionEnd = xunfei.NewProc("xfQISRSessionEnd")
procQISRSetParam = xunfei.NewProc("xfQISRSetParam")
procQISRUpdateLexicon = xunfei.NewProc("xfQISRUpdateLexicon")
procQIVWAudioWrite = xunfei.NewProc("xfQIVWAudioWrite")
procQIVWRegisterNotify = xunfei.NewProc("xfQIVWRegisterNotify")
procQIVWResMerge = xunfei.NewProc("xfQIVWResMerge")
procQIVWSessionBegin = xunfei.NewProc("xfQIVWSessionBegin")
procQIVWSessionEnd = xunfei.NewProc("xfQIVWSessionEnd")
procQTTSAudioGet = xunfei.NewProc("xfQTTSAudioGet")
procQTTSAudioInfo = xunfei.NewProc("xfQTTSAudioInfo")
procQTTSGetParam = xunfei.NewProc("xfQTTSGetParam")
procQTTSSessionBegin = xunfei.NewProc("xfQTTSSessionBegin")
procQTTSSessionEnd = xunfei.NewProc("xfQTTSSessionEnd")
procQTTSSetParam = xunfei.NewProc("xfQTTSSetParam")
procQTTSTextPut = xunfei.NewProc("xfQTTSTextPut")
)
type NLPSearchCB func()
type MSP_STATUS_NTF_HANDLER func()
type GrammarCallBack func()
type LexiconCallBack func()
type MsgProcCallBack func()
// const void* MSPAPI MSPDownloadData(const char* params, unsigned int* dataLen, int* errorCode);
func MSPDownloadData(params string) ([]byte, error) {
var dataLen int
var errorCode int
r1, _, _ := procMSPDownloadData.Call(
uintptr(unsafeString(params)),
uintptr(unsafe.Pointer(&dataLen)),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return nil, fmt.Errorf("MSPDownloadData failed, error %d", errorCode)
}
return uintptrToBytes(r1, dataLen), nil
}
// int MSPAPI MSPGetParam( const char *paramName, char *paramValue, unsigned int *valueLen );
func MSPGetParam(paramName string) (string, error) {
var valueLen uint
var pValue = make([]byte, 32)
r1, _, _ := procMSPGetParam.Call(
uintptr(unsafeString(paramName)),
uintptr(unsafe.Pointer(&pValue[0])),
uintptr(unsafe.Pointer(&valueLen)))
if r1 != MSP_SUCCESS {
return "", fmt.Errorf("MSPGetParam failed, error %d", r1)
}
return string(pValue), nil
}
// const char* MSPAPI MSPGetVersion(const char *verName, int *errorCode);
func MSPGetVersion(verName string) (string, error) {
var errorCode int
r1, _, _ := procMSPGetVersion.Call(
uintptr(unsafeString(verName)),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return "", fmt.Errorf("MSPGetVersion failed, error %d", errorCode)
}
return uintptrToString(r1), nil
}
// int MSPAPI MSPLogin(const char* usr, const char* pwd, const char* params);
func MSPLogin(params string) error {
r1, _, _ := procMSPLogin.Call(
uintptr(0),
uintptr(0),
uintptr(unsafeString(params)))
if r1 != MSP_SUCCESS {
return fmt.Errorf("MSPLogin failed, error %d", int(r1))
}
return nil
}
// int MSPAPI MSPLogout();
func MSPLogout() error {
r1, _, _ := procMSPLogout.Call()
if r1 != MSP_SUCCESS {
return fmt.Errorf("MSPLogout failed, error %d", r1)
}
return nil
}
// int MSPAPI MSPNlpSchCancel(const char *sessionID, const char *hints);
func MSPNlpSchCancel(sessionID string, hints string) error {
r1, _, _ := procMSPNlpSchCancel.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafeString(hints)))
if r1 != MSP_SUCCESS {
return fmt.Errorf("MSPNlpSchCancel failed, error %d", int(r1))
}
return nil
}
// const char* MSPAPI MSPNlpSearch(const char* params, const char* text, unsigned int textLen, int *errorCode, NLPSearchCB callback, void *userData);
// const char* MSPAPI MSPNlpSearch(const char* params,
// const char* text,
// unsigned int textLen,
// int *errorCode,
// NLPSearchCB callback,
// void *userData);
func MSPNlpSearch(params string, text string, callback NLPSearchCB) (string, []byte, error) {
var errorCode int
var textLen = len(text)
var userData = make([]byte, 256*1024)
r1, _, _ := procMSPNlpSearch.Call(
uintptr(unsafeString(params)),
uintptr(unsafeString(text)),
uintptr(textLen),
uintptr(unsafe.Pointer(&errorCode)),
uintptr(syscall.NewCallback(callback)),
uintptr(unsafe.Pointer(&userData[0])))
if errorCode != MSP_SUCCESS {
return "", nil, fmt.Errorf("MSPNlpSearch failed, error %d", int(errorCode))
}
return uintptrToString(r1), userData, nil
}
// int MSPAPI MSPRegisterNotify( msp_status_ntf_handler statusCb, void *userData );
func MSPRegisterNotify(statusCb MSP_STATUS_NTF_HANDLER) ([]byte, error) {
var userData = make([]byte, 256*1024)
r1, _, _ := procMSPRegisterNotify.Call(
uintptr(syscall.NewCallback(statusCb)),
uintptr(unsafe.Pointer(&userData[0])))
if r1 != MSP_SUCCESS {
return nil, fmt.Errorf("MSPRegisterNotify failed, error %d", int(r1))
}
return userData, nil
}
// const char* MSPAPI MSPSearch(const char* params, const char* text, unsigned int* dataLen, int* errorCode);
func MSPSearch(params string, text string) (string, error) {
var dataLen uint
var errorCode int
r1, _, _ := procMSPSearch.Call(
uintptr(unsafeString(params)),
uintptr(unsafeString(text)),
uintptr(unsafe.Pointer(&dataLen)),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return "", fmt.Errorf("MSPSearch failed, error %d", int(errorCode))
}
return uintptrToString(r1), nil
}
// int MSPAPI MSPSetParam( const char* paramName, const char* paramValue );
func MSPSetParam(paramName string, paramValue string) error {
r1, _, _ := procMSPSetParam.Call(
uintptr(unsafeString(paramName)),
uintptr(unsafeString(paramValue)))
if r1 != MSP_SUCCESS {
return fmt.Errorf("MSPSetParam failed, error %d", int(r1))
}
return nil
}
// const char* MSPAPI MSPUploadData(const char* dataName, void* data, unsigned int dataLen, const char* params, int* errorCode);
func MSPUploadData(dataName string, data []byte, params string) (string, error) {
var errorCode int
r1, _, _ := procMSPUploadData.Call(
uintptr(unsafeString(dataName)),
uintptr(unsafe.Pointer(&data[0])),
uintptr(len(data)),
uintptr(unsafeString(params)),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return "", fmt.Errorf("MSPUploadData failed, error %d", int(errorCode))
}
return uintptrToString(r1), nil
}
// int MSPAPI QISEAudioWrite(const char* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *Status);
func QISEAudioWrite(sessionID string, waveData []byte, audioStatus int) (int, int, error) {
var epStatus int
var Status int
var waveLen = len(waveData)
r1, _, _ := procQISEAudioWrite.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafe.Pointer(&waveData[0])),
uintptr(waveLen),
uintptr(audioStatus),
uintptr(unsafe.Pointer(&epStatus)),
uintptr(unsafe.Pointer(&Status)))
if r1 != MSP_SUCCESS {
return 0, 0, fmt.Errorf("QISEAudioWrite failed, error %d", int(r1))
}
return epStatus, Status, nil
}
// int MSPAPI QISEGetParam(const char* sessionID, const char* paramName, char* paramValue, unsigned int* valueLen);
func QISEGetParam(sessionID string, paramName string) (string, error) {
var valueLen uint
var pValue = make([]byte, 64)
r1, _, _ := procQISEGetParam.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafeString(paramName)),
uintptr(unsafe.Pointer(&pValue[0])),
uintptr(unsafe.Pointer(&valueLen)))
if r1 != MSP_SUCCESS {
return "", fmt.Errorf("QISEGetParam failed, error %d", int(r1))
}
return string(pValue[:valueLen]), nil
}
// const char * MSPAPI QISEGetResult(const char* sessionID, unsigned int* rsltLen, int* rsltStatus, int *errorCode);
func QISEGetResult(sessionID string) (string, int, error) {
var rsltLen int
var rsltStatus int
var errorCode int
r1, _, _ := procQISEGetResult.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafe.Pointer(&rsltLen)),
uintptr(unsafe.Pointer(&rsltStatus)),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return "", 0, fmt.Errorf("QISEGetResult failed, error %d", errorCode)
}
return string(uintptrToBytes(r1, rsltLen)), rsltStatus, nil
}
// const char* MSPAPI QISEResultInfo(const char* sessionID, int *errorCode);
func QISEResultInfo(sessionID string) (string, error) {
var errorCode int
r1, _, _ := procQISEResultInfo.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return "", fmt.Errorf("QISEResultInfo failed, error %d", int(errorCode))
}
return uintptrToString(r1), nil
}
// const char* MSPAPI QISESessionBegin(const char* params, const char* userModelId, int* errorCode);
func QISESessionBegin(params string, userModelId string) (string, error) {
var errorCode int
r1, _, _ := procQISESessionBegin.Call(
uintptr(unsafeString(params)),
uintptr(unsafeString(userModelId)),
uintptr(unsafe.Pointer(&errorCode)))
if r1 != MSP_SUCCESS {
return "", fmt.Errorf("QISESessionBegin failed, error %d", int(errorCode))
}
return uintptrToString(r1), nil
}
// int MSPAPI QISESessionEnd(const char* sessionID, const char* hints);
func QISESessionEnd(sessionID string, hints string) error {
r1, _, _ := procQISESessionEnd.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafeString(hints)))
if r1 != MSP_SUCCESS {
return fmt.Errorf("QISESessionEnd failed, error %d", int(r1))
}
return nil
}
// int MSPAPI QISETextPut(const char* sessionID, const char* textString, unsigned int textLen, const char* params);
func QISETextPut(sessionID string, textString string, params string) error {
var textLen = len([]byte(textString))
r1, _, _ := procQISETextPut.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafeString(textString)),
uintptr(textLen),
uintptr(unsafeString(params)))
if r1 != MSP_SUCCESS {
return fmt.Errorf("QISESessionEnd failed, error %d", int(r1))
}
return nil
}
// int MSPAPI QISRAudioWrite(const char* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *recogStatus);
func QISRAudioWrite(sessionID string, waveData []byte, audioStatus int) (int, int, error) {
var epStatus int
var recogStatus int
var data unsafe.Pointer
var waveLen = len(waveData)
if waveData == nil {
data = nil
} else {
data = unsafe.Pointer(&waveData[0])
}
r1, _, _ := procQISRAudioWrite.Call(
uintptr(unsafeString(sessionID)),
uintptr(data),
uintptr(waveLen),
uintptr(audioStatus),
uintptr(unsafe.Pointer(&epStatus)),
uintptr(unsafe.Pointer(&recogStatus)))
if r1 != MSP_SUCCESS {
return 0, 0, fmt.Errorf("QISRAudioWrite failed, error %d", int(r1))
}
return epStatus, recogStatus, nil
}
// int MSPAPI QISRBuildGrammar(const char *grammarType, const char *grammarContent, unsigned int grammarLength, const char *params, GrammarCallBack callback, void *userData);
func QISRBuildGrammar(grammarType string, grammarContent string, params string, callback GrammarCallBack) ([]byte, error) {
var grammarLength = len([]byte(grammarContent))
var userData = make([]byte, 256*1024)
r1, _, _ := procQISRBuildGrammar.Call(
uintptr(unsafeString(grammarType)),
uintptr(unsafeString(grammarContent)),
uintptr(grammarLength),
uintptr(unsafeString(params)),
syscall.NewCallback(callback),
uintptr(unsafe.Pointer(&userData[0])))
if r1 != MSP_SUCCESS {
return nil, fmt.Errorf("QISRBuildGrammar failed, error %d", r1)
}
return userData, nil
}
// const char * MSPAPI QISRGetBinaryResult(const char* sessionID, unsigned int* rsltLen,int* rsltStatus, int waitTime, int *errorCode);
func QISRGetBinaryResult(sessionID string, waitTime int) (string, int, error) {
var rsltLen int
var rsltStatus int
var errorCode int
r1, _, _ := procQISRGetBinaryResult.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafe.Pointer(&rsltLen)),
uintptr(unsafe.Pointer(&rsltStatus)),
uintptr(waitTime),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return "", 0, fmt.Errorf("QISRGetBinaryResult failed, error %d", int(errorCode))
}
return string(uintptrToBytes(r1, rsltLen)), rsltStatus, nil
}
// int MSPAPI QISRGetParam(const char* sessionID, const char* paramName, char* paramValue, unsigned int* valueLen);
func QISRGetParam(sessionID string, paramName string) (string, error) {
var valueLen int
var pValue = make([]byte, 32)
r1, _, _ := procQISRGetParam.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafeString(paramName)),
uintptr(unsafe.Pointer(&pValue[0])),
uintptr(unsafe.Pointer(&valueLen)))
if r1 != MSP_SUCCESS {
return "", fmt.Errorf("QISRGetParam failed, error %d", int(r1))
}
return string(pValue[:valueLen]), nil
}
// const char * MSPAPI QISRGetResult(const char* sessionID, int* rsltStatus, int waitTime, int *errorCode);
func QISRGetResult(sessionID string, recStat int, waitTime int) (string, int, error) {
var rsltStatus = recStat
var errorCode int
r1, _, _ := procQISRGetResult.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafe.Pointer(&rsltStatus)),
uintptr(waitTime),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return "", 0, fmt.Errorf("QISRGetResult failed, error %d", int(errorCode))
}
return uintptrToString(r1), rsltStatus, nil
}
// const char* MSPAPI QISRSessionBegin(const char* grammarList, const char* params, int* errorCode);
func QISRSessionBegin(grammarList string, params string) (string, error) {
var errorCode int
r1, _, _ := procQISRSessionBegin.Call(
uintptr(unsafeString(grammarList)),
uintptr(unsafeString(params)),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return "", fmt.Errorf("QISRSessionBegin failed, error %d", int(errorCode))
}
return uintptrToString(r1), nil
}
// int MSPAPI QISRSessionEnd(const char* sessionID, const char* hints);
func QISRSessionEnd(sessionID string, hints string) error {
r1, _, _ := procQISRSessionEnd.Call(
uintptr(unsafeString(sessionID)),
uintptr(0))
if r1 != MSP_SUCCESS {
return fmt.Errorf("QISRSessionEnd failed, error %d", int(r1))
}
return nil
}
// int MSPAPI QISRSetParam(const char* sessionID, const char* paramName, const char* paramValue);
func QISRSetParam(sessionID string, paramName string, paramValue string) error {
r1, _, _ := procQISRSetParam.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafeString(paramName)),
uintptr(unsafeString(paramValue)))
if r1 != MSP_SUCCESS {
return fmt.Errorf("QISRSetParam failed, error %d", int(r1))
}
return nil
}
// int MSPAPI QISRUpdateLexicon(const char *lexiconName, const char *lexiconContent, unsigned int lexiconLength, const char *params, LexiconCallBack callback, void *userData);
func QISRUpdateLexicon(lexiconName string, lexiconContent string, params string, callback LexiconCallBack) ([]byte, error) {
var lexiconLength = len([]byte(lexiconContent))
var userData = make([]byte, 256*1024)
r1, _, _ := procQISRUpdateLexicon.Call(
uintptr(unsafeString(lexiconName)),
uintptr(unsafeString(lexiconContent)),
uintptr(lexiconLength),
uintptr(unsafeString(params)),
uintptr(unsafe.Pointer(&userData[0])))
if r1 != MSP_SUCCESS {
return nil, fmt.Errorf("QISRUpdateLexicon failed, error %d", int(r1))
}
return userData, nil
}
// int MSPAPI QIVWAudioWrite(const char *sessionID, const void *audioData, unsigned int audioLen, int audioStatus);
func QIVWAudioWrite(sessionID string, audioData []byte, audioStatus int) error {
var audioLen = len(audioData)
r1, _, _ := procQIVWAudioWrite.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafe.Pointer(&audioData[0])),
uintptr(audioLen),
uintptr(audioStatus))
if r1 != MSP_SUCCESS {
return fmt.Errorf("QIVWAudioWrite failed, error %d", int(r1))
}
return nil
}
// int MSPAPI QIVWRegisterNotify(const char *sessionID, ivw_ntf_handler msgProcCb, void *userData);
func QIVWRegisterNotify(sessionID string, userData []byte, ivw_ntf_handler MsgProcCallBack) error {
r1, _, _ := procQIVWRegisterNotify.Call(
uintptr(unsafeString(sessionID)),
syscall.NewCallback(ivw_ntf_handler),
uintptr(unsafe.Pointer(&userData[0])))
if r1 != MSP_SUCCESS {
return fmt.Errorf("QIVWRegisterNotify failed, error %d", int(r1))
}
return nil
}
// int MSPAPI QIVWResMerge(const char *srcPath, const char *destPath, const char *params);
func QIVWResMerge(srcPath string, destPath string, params string) error {
r1, _, _ := procQIVWResMerge.Call(
uintptr(unsafeString(srcPath)),
uintptr(unsafeString(destPath)),
uintptr(unsafeString(params)))
if r1 != MSP_SUCCESS {
return fmt.Errorf("QIVWResMerge failed, error %d", int(r1))
}
return nil
}
// const char* MSPAPI QIVWSessionBegin(const char *grammarList, const char *params, int *errorCode);
func QIVWSessionBegin(grammarList string, params string) (string, error) {
var errorCode int
r1, _, _ := procQIVWSessionBegin.Call(
uintptr(unsafeString(grammarList)),
uintptr(unsafeString(params)),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return "", fmt.Errorf("QIVWSessionBegin failed, error %d", int(errorCode))
}
return uintptrToString(r1), nil
}
// int MSPAPI QIVWSessionEnd(const char *sessionID, const char *hints);
func QIVWSessionEnd(sessionID string, hints string) error {
r1, _, _ := procQIVWSessionEnd.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafeString(hints)))
if r1 != MSP_SUCCESS {
return fmt.Errorf("QIVWSessionEnd failed, error %d", int(r1))
}
return nil
}
// const void* MSPAPI QTTSAudioGet(const char* sessionID, unsigned int* audioLen, int* synthStatus, int* errorCode);
func QTTSAudioGet(sessionID string) ([]byte, int, error) {
var audioLen int
var synthStatus int
var errorCode int
r1, _, _ := procQTTSAudioGet.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafe.Pointer(&audioLen)),
uintptr(unsafe.Pointer(&synthStatus)),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return nil, 0, fmt.Errorf("QTTSAudioGet failed, error %d", int(errorCode))
}
return uintptrToBytes(r1, audioLen), synthStatus, nil
}
// const char* MSPAPI QTTSAudioInfo(const char* sessionID);
func QTTSAudioInfo(sessionID string) string {
r1, _, _ := procQTTSAudioInfo.Call(uintptr(unsafeString(sessionID)))
return uintptrToString(r1)
}
// int MSPAPI QTTSGetParam(const char* sessionID, const char* paramName, char* paramValue, unsigned int* valueLen);
func QTTSGetParam(sessionID string, paramName string) (string, error) {
var valueLen uint
var pValue = make([]byte, 32)
r1, _, _ := procQTTSGetParam.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafeString(paramName)),
uintptr(unsafe.Pointer(&pValue[0])),
uintptr(unsafe.Pointer(&valueLen)))
if r1 != MSP_SUCCESS {
return "", fmt.Errorf("QTTSGetParam failed, error %d", int(r1))
}
return string(pValue[:valueLen]), nil
}
// const char* MSPAPI QTTSSessionBegin(const char* params, int* errorCode);
func QTTSSessionBegin(params string) (string, error) {
var errorCode int
r1, _, _ := procQTTSSessionBegin.Call(
uintptr(unsafeString(params)),
uintptr(unsafe.Pointer(&errorCode)))
if errorCode != MSP_SUCCESS {
return "", fmt.Errorf("QTTSSessionBegin failed, error %d", int(errorCode))
}
return uintptrToString(r1), nil
}
// int MSPAPI QTTSSessionEnd(const char* sessionID, const char* hints);
func QTTSSessionEnd(sessionID string, hints string) error {
r1, _, _ := procQTTSSessionEnd.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafeString(hints)))
if r1 != MSP_SUCCESS {
return fmt.Errorf("QTTSSessionEnd failed, error %d", int(r1))
}
return nil
}
// int MSPAPI QTTSSetParam(const char *sessionID, const char *paramName, const char *paramValue);
func QTTSSetParam(sessionID string, paramName string, paramValue string) error {
r1, _, _ := procQTTSSetParam.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafeString(paramName)),
uintptr(unsafeString(paramValue)))
if r1 != MSP_SUCCESS {
return fmt.Errorf("QTTSSetParam failed, error %d", int(r1))
}
return nil
}
// int MSPAPI QTTSTextPut(const char* sessionID, const char* textString, unsigned int textLen, const char* params);
func QTTSTextPut(sessionID string, textString string, params string) error {
var textLen = len([]byte(textString))
r1, _, _ := procQTTSTextPut.Call(
uintptr(unsafeString(sessionID)),
uintptr(unsafeString(textString)),
uintptr(textLen),
uintptr(unsafeString(params)))
if r1 != MSP_SUCCESS {
return fmt.Errorf("QTTSTextPut failed, error %d", int(r1))
}
return nil
}