1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  *
4  */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <stdint.h>
9 #include <string.h>
10 
11 #include "uvoice_types.h"
12 #include "uvoice_tts.h"
13 
14 #include "../../../internal/uvoice_os.h"
15 
16 static tts_aicloud_type_e g_aicloud_type;
17 static uvoice_tts_t *g_uvoice_tts;
18 
uvoice_tts_init(tts_aicloud_type_e aicloud_type,tts_config_t * config)19 static int uvoice_tts_init(tts_aicloud_type_e aicloud_type, tts_config_t *config)
20 {
21 	g_aicloud_type = aicloud_type;
22 	if (aicloud_type == TTS_AICLOUD_ALIYUN) {
23 #ifdef ALICLOUD_TTS_SUPPORT
24 		return uvoice_tts_aliyun_init(config);
25 #else
26 		return -1;
27 #endif
28 	}
29 
30 	return -1;
31 }
32 
uvoice_tts_request(char * text,tts_recv_type_e recv_type,tts_recv_callback_t * recv_cb)33 static int uvoice_tts_request(char *text, tts_recv_type_e recv_type,
34 	tts_recv_callback_t *recv_cb)
35 {
36     if(g_aicloud_type == TTS_AICLOUD_ALIYUN) {
37 #ifdef ALICLOUD_TTS_SUPPORT
38         return uvoice_tts_aliyun_request(text, recv_type, recv_cb);
39 #else
40         return -1;
41 #endif
42     }
43 
44     return -1;
45 }
46 
uvoice_tts_stop()47 static int uvoice_tts_stop()
48 {
49 	if(g_aicloud_type == TTS_AICLOUD_ALIYUN) {
50 #ifdef ALICLOUD_TTS_SUPPORT
51 		return uvoice_tts_stop();
52 #else
53 		return -1;
54 #endif
55 	}
56 
57 	return -1;
58 }
59 
uvoice_tts_create(void)60 uvoice_tts_t *uvoice_tts_create(void)
61 {
62 	uvoice_tts_t *uvoice_tts = g_uvoice_tts;
63 
64 	if (uvoice_tts)
65 		return uvoice_tts;
66 
67 	uvoice_tts = snd_zalloc(sizeof(uvoice_tts_t), AFM_EXTN);
68 	if (!uvoice_tts) {
69 		M_LOGE("alloc uvoice_tts failed !\n");
70 		return NULL;
71 	}
72 
73 	g_uvoice_tts = uvoice_tts;
74 
75 	uvoice_tts->tts_init = uvoice_tts_init;
76 	uvoice_tts->tts_request = uvoice_tts_request;
77 	uvoice_tts->tts_stop = uvoice_tts_stop;
78 
79 	M_LOGI("uvoice tts create\n");
80 	return uvoice_tts;
81 }
82 
uvoice_tts_release(uvoice_tts_t * uvoice_tts)83 int uvoice_tts_release(uvoice_tts_t *uvoice_tts)
84 {
85 	if (uvoice_tts) {
86 		snd_free(uvoice_tts);
87 		g_uvoice_tts = NULL;
88 		M_LOGI("uvoice tts release\n");
89 	}
90 	return 0;
91 }
92 
93