FreeSWITCH API Documentation  1.7.0
switch_ivr_say.c
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Anthony Minessale II <anthm@freeswitch.org>
27  * Michael Jerris <mike@jerris.com>
28  *
29  * switch_ivr_say.c -- IVR Library (functions to say audio in languages)
30  *
31  */
32 
33 #include <switch.h>
34 
35 static char *SAY_METHOD_NAMES[] = {
36  "N/A",
37  "PRONOUNCED",
38  "ITERATED",
39  "COUNTED",
40  "PRONOUNCED_YEAR",
41  NULL
42 };
43 
44 static char *SAY_TYPE_NAMES[] = {
45  "NUMBER",
46  "ITEMS",
47  "PERSONS",
48  "MESSAGES",
49  "CURRENCY",
50  "TIME_MEASUREMENT",
51  "CURRENT_DATE",
52  "CURRENT_TIME",
53  "CURRENT_DATE_TIME",
54  "TELEPHONE_NUMBER",
55  "TELEPHONE_EXTENSION",
56  "URL",
57  "IP_ADDRESS",
58  "EMAIL_ADDRESS",
59  "POSTAL_ADDRESS",
60  "ACCOUNT_NUMBER",
61  "NAME_SPELLED",
62  "NAME_PHONETIC",
63  "SHORT_DATE_TIME",
64  NULL
65 };
66 
67 static char *SAY_GENDER_NAMES[] = {
68  "MASCULINE",
69  "FEMININE",
70  "NEUTER",
71  NULL
72 };
73 
75 {
76  int x = 0;
77 
78  if (!name) return (switch_say_gender_t)0;
79 
80  for (x = 0; SAY_GENDER_NAMES[x]; x++) {
81  if (!strcasecmp(SAY_GENDER_NAMES[x], name)) {
82  break;
83  }
84  }
85 
86  return (switch_say_gender_t) x;
87 }
88 
90 {
91  int x = 0;
92 
93  if (!name) return (switch_say_method_t)0;
94 
95  for (x = 0; SAY_METHOD_NAMES[x]; x++) {
96  if (!strcasecmp(SAY_METHOD_NAMES[x], name)) {
97  break;
98  }
99  }
100 
101  return (switch_say_method_t) x;
102 }
103 
105 {
106  int x = 0;
107 
108  if (!name) return (switch_say_type_t)0;
109 
110  for (x = 0; SAY_TYPE_NAMES[x]; x++) {
111  if (!strcasecmp(SAY_TYPE_NAMES[x], name)) {
112  break;
113  }
114  }
115 
116  return (switch_say_type_t) x;
117 }
118 
119 #define say_file(...) { \
120  char tmp[80]; \
121  switch_status_t tstatus; \
122  switch_snprintf(tmp, sizeof(tmp), __VA_ARGS__); \
123  if ((tstatus = \
124  switch_ivr_play_file(session, NULL, tmp, args)) \
125  != SWITCH_STATUS_SUCCESS){ \
126  return tstatus; \
127  } \
128  if (!switch_channel_ready(switch_core_session_get_channel(session))) { \
129  return SWITCH_STATUS_FALSE; \
130  }} \
131 
132 
134 {
135  char *p;
136 
138 
139  for (p = tosay; p && *p; p++) {
140  int a = tolower((int) *p);
141  if (a >= '0' && a <= '9') {
142  say_file("digits/%d.wav", a - '0');
143  } else {
144  if (say_args->type == SST_NAME_SPELLED) {
145  say_file("ascii/%d.wav", a);
146  } else if (say_args->type == SST_NAME_PHONETIC) {
147  say_file("phonetic-ascii/%d.wav", a);
148  }
149  }
150  }
151 
153 
154  return SWITCH_STATUS_SUCCESS;
155 }
156 
157 #define say_num(num, meth) { \
158  char tmp[80]; \
159  switch_status_t tstatus; \
160  switch_say_method_t smeth = say_args->method; \
161  switch_say_type_t stype = say_args->type; \
162  say_args->type = SST_ITEMS; say_args->method = meth; \
163  switch_snprintf(tmp, sizeof(tmp), "%u", (unsigned)num); \
164  if ((tstatus = \
165  number_func(session, tmp, say_args, args)) \
166  != SWITCH_STATUS_SUCCESS) { \
167  return tstatus; \
168  } \
169  say_args->method = smeth; say_args->type = stype; \
170  } \
171 
173  char *tosay,
174  switch_say_callback_t number_func,
175  switch_say_args_t *say_args,
176  switch_input_args_t *args)
177 {
178  char *a, *b, *c, *d;
180 
182 
183  if (!(a = switch_core_session_strdup(session, tosay))) {
185  }
186 
187  if (!(b = strchr(a, '.'))) {
189  }
190 
191  *b++ = '\0';
192 
193  if (!(c = strchr(b, '.'))) {
195  }
196 
197  *c++ = '\0';
198 
199  if (!(d = strchr(c, '.'))) {
201  }
202 
203  *d++ = '\0';
204 
205  say_num(atoi(a), say_args->method);
206  say_file("digits/dot.wav");
207  say_num(atoi(b), say_args->method);
208  say_file("digits/dot.wav");
209  say_num(atoi(c), say_args->method);
210  say_file("digits/dot.wav");
211  say_num(atoi(d), say_args->method);
212 
213  end:
214 
216 
217  return status;
218 }
219 
220 
221 /* For Emacs:
222  * Local Variables:
223  * mode:c
224  * indent-tabs-mode:t
225  * tab-width:4
226  * c-basic-offset:4
227  * End:
228  * For VIM:
229  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
230  */
switch_say_type_t switch_ivr_get_say_type_by_name(const char *name)
static char * SAY_METHOD_NAMES[]
switch_say_gender_t switch_ivr_get_say_gender_by_name(const char *name)
#define arg_recursion_check_stop(_args)
switch_status_t(* switch_say_callback_t)(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
#define say_num(num, meth)
#define say_file(...)
static char * SAY_GENDER_NAMES[]
switch_say_gender_t
Definition: switch_types.h:442
#define arg_recursion_check_start(_args)
switch_status_t
Common return values.
switch_status_t switch_ivr_say_spell(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:256
Main Library Header.
#define SWITCH_DECLARE(type)
switch_status_t switch_ivr_say_ip(switch_core_session_t *session, char *tosay, switch_say_callback_t number_func, switch_say_args_t *say_args, switch_input_args_t *args)
switch_say_type_t
Definition: switch_types.h:420
switch_say_method_t switch_ivr_get_say_method_by_name(const char *name)
switch_say_method_t
Definition: switch_types.h:411
#define switch_core_session_strdup(_session, _todup)
Copy a string using memory allocation from a session's pool.
Definition: switch_core.h:717
static char * SAY_TYPE_NAMES[]