1999-10-30 01:01:34 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- A telephony toolkit for Linux.
|
|
|
|
*
|
|
|
|
* Say numbers and dates (maybe words one day too)
|
|
|
|
*
|
1999-12-11 20:09:45 +00:00
|
|
|
* Copyright (C) 1999, Mark Spencer
|
1999-10-30 01:01:34 +00:00
|
|
|
*
|
|
|
|
* Mark Spencer <markster@linux-support.net>
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asterisk/file.h>
|
|
|
|
#include <asterisk/channel.h>
|
|
|
|
#include <asterisk/logger.h>
|
|
|
|
#include <asterisk/say.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2000-01-09 19:58:18 +00:00
|
|
|
int ast_say_digit_str(struct ast_channel *chan, char *fn2, char *lang)
|
1999-10-30 01:01:34 +00:00
|
|
|
{
|
|
|
|
char fn[256] = "";
|
|
|
|
int num = 0;
|
|
|
|
int res = 0;
|
|
|
|
while(fn2[num] && !res) {
|
|
|
|
snprintf(fn, sizeof(fn), "digits/%c", fn2[num]);
|
2000-01-09 19:58:18 +00:00
|
|
|
res = ast_streamfile(chan, fn, lang);
|
1999-10-30 01:01:34 +00:00
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(chan, AST_DIGIT_ANY);
|
|
|
|
ast_stopstream(chan);
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-01-09 19:58:18 +00:00
|
|
|
int ast_say_digits(struct ast_channel *chan, int num, char *lang)
|
1999-10-30 01:01:34 +00:00
|
|
|
{
|
|
|
|
char fn2[256];
|
|
|
|
snprintf(fn2, sizeof(fn2), "%d", num);
|
2000-01-09 19:58:18 +00:00
|
|
|
return ast_say_digit_str(chan, fn2, lang);
|
1999-10-30 01:01:34 +00:00
|
|
|
}
|
2000-01-09 19:58:18 +00:00
|
|
|
int ast_say_number(struct ast_channel *chan, int num, char *language)
|
1999-10-30 01:01:34 +00:00
|
|
|
{
|
|
|
|
int res = 0;
|
2000-01-02 20:59:00 +00:00
|
|
|
int playh = 0;
|
1999-10-30 01:01:34 +00:00
|
|
|
char fn[256] = "";
|
2000-01-09 19:58:18 +00:00
|
|
|
if (0) {
|
|
|
|
/* XXX Only works for english XXX */
|
|
|
|
} else {
|
|
|
|
/* Use english numbers */
|
|
|
|
language = "en";
|
|
|
|
while(num && !res) {
|
|
|
|
if (playh) {
|
|
|
|
snprintf(fn, sizeof(fn), "digits/hundred");
|
|
|
|
playh = 0;
|
|
|
|
} else
|
|
|
|
if (num < 20) {
|
|
|
|
snprintf(fn, sizeof(fn), "digits/%d", num);
|
|
|
|
num = 0;
|
|
|
|
} else
|
|
|
|
if (num < 100) {
|
|
|
|
snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
|
|
|
|
num -= ((num / 10) * 10);
|
2000-01-02 20:59:00 +00:00
|
|
|
} else {
|
2000-01-09 19:58:18 +00:00
|
|
|
if (num < 1000){
|
|
|
|
snprintf(fn, sizeof(fn), "digits/%d", (num/100));
|
|
|
|
playh++;
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
|
|
|
|
res = -1;
|
|
|
|
}
|
2000-01-02 20:59:00 +00:00
|
|
|
}
|
2000-01-09 19:58:18 +00:00
|
|
|
if (!res) {
|
|
|
|
res = ast_streamfile(chan, fn, language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(chan, AST_DIGIT_ANY);
|
|
|
|
ast_stopstream(chan);
|
|
|
|
}
|
|
|
|
|
1999-10-30 01:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|