提交 9a43ccab authored 作者: Anthony Minessale's avatar Anthony Minessale

add mod_rss

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1551 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 cd3e5e83
......@@ -58,6 +58,7 @@
<!-- ASR /TTS -->
<!-- <load module="mod_cepstral"/> -->
<!-- <load module="mod_rss"/> -->
</modules>
</configuration>
......
......@@ -6,6 +6,7 @@ applications/mod_echo
applications/mod_ivrtest
applications/mod_playback
applications/mod_skel
#applications/mod_rss
#asr_tts/mod_cepstral
codecs/mod_g711
codecs/mod_ilbc
......
#!/usr/local/bin/perl
##########################################################################
# rss2ivr.pl -- A Script to turn an RSS feed into audio files.
#
# Copyright (C) 2006, Anthony Minessale
#
# Anthony Minessale <anthmct@yahoo.com>
#
# This program is free software, distributed under the terms of
# Perl itself
##########################################################################
use XML::RSS;
require LWP::UserAgent;
################################################################################
my $swift = "/opt/swift/bin/swift";
################################################################################
my $rss = new XML::RSS;
my $root = shift;
my $target = shift;
my $dir = shift;
my $saytxt;
my $voice = shift || "David";
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
unless($root and $target and $dir) {
die("Usage: $0 <root dir> <target url> <ivr name>\n");
}
unless(-d $root) {
mkdir($root);
}
chdir($root) or die("where is $root");
if ($target =~ /http/) {
my $response = $ua->get($target);
if ($response->is_success) {
$in = $response->content;
} else {
die $response->status_line;
}
my $x = 1;
$rss->parse($in);
system("rm -fr $$");
mkdir($$);
die unless(-d $$);
chdir($$);
open(I,">00.txt");
print I "$dir main index.\n";
foreach my $item (@{$rss->{'items'}}) {
my $xx = sprintf("%0.2d", $x);
my $title .= "entry $xx, " . $item->{'title'} . ".\n";
print I $title;
my $desc = $item->{'description'};
$desc =~ s/\<[^\>]+\>//g;
my $content = "entry $xx.\n" . $item->{'title'} . ".\n". $desc;
open(X,">$xx.txt");
$content =~ s/[^\w\d\s \.\,\-\n]//smg;
print X $content;
close X;
my $do = "$swift -p audio/deadair=2000,audio/sampling-rate=8000,audio/channels=1,audio/encoding=pcm16,audio/output-format=raw -o ${xx}.raw -f ${xx}.txt -n $voice";
system $do;
$x++;
}
my $do = "$swift -p audio/deadair=2000,audio/sampling-rate=8000,audio/channels=1,audio/encoding=pcm16,audio/output-format=raw -o 00.raw -f 00.txt -n $voice";
system $do;
close(I);
chdir("..");
system("/bin/rm -fr $dir");
system("/bin/mv -f $$ $dir");
}
......@@ -362,6 +362,13 @@ SWITCH_DECLARE(switch_size_t) switch_channel_dequeue_dtmf(switch_channel_t *chan
*/
SWITCH_DECLARE(const char *) switch_channel_state_name(switch_channel_state_t state);
/*!
\brief Render the enum of the provided state name
\param name the name of the state
\return the enum value (numeric)
*/
SWITCH_DECLARE(switch_channel_state_t) switch_channel_name_state(char *name);
/*!
\brief Add information about a given channel to an event object
\param channel channel to add information about
......
......@@ -231,6 +231,7 @@ typedef enum {
SWITCH_STATUS_BREAK - A non-fatal break of an operation
SWITCH_STATUS_SOCKERR - A socket error
SWITCH_STATUS_MORE_DATA - Need More Data
SWITCH_STATUS_NOTFOUND - Not Found
</pre>
*/
typedef enum {
......@@ -247,7 +248,8 @@ typedef enum {
SWITCH_STATUS_INUSE,
SWITCH_STATUS_BREAK,
SWITCH_STATUS_SOCKERR,
SWITCH_STATUS_MORE_DATA
SWITCH_STATUS_MORE_DATA,
SWITCH_STATUS_NOTFOUND
} switch_status_t;
......
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
*
*
* mod_rss.c -- RSS Browser
*
*/
#include <switch.h>
static const char modname[] = "mod_rss";
/* helper object */
struct dtmf_buffer {
char *data;
char *front;
uint32_t len;
uint32_t size;
switch_file_handle_t fh;
};
/*
dtmf handler function you can hook up to be executed when a digit is dialed during playback
if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
*/
static switch_status_t on_dtmf(switch_core_session_t *session, char *dtmf, void *buf, unsigned int buflen)
{
struct dtmf_buffer *dtb;
uint32_t len, slen;
dtb = (struct dtmf_buffer *) buf;
uint32_t samps = 0, pos = 0;
if (*dtmf == '#') {
return SWITCH_STATUS_FALSE;
}
len = dtb->size - dtb->len;
slen = strlen(dtmf);
if (slen > len) {
slen = len;
}
switch_copy_string(dtb->front, dtmf, len);
dtb->front += slen;
dtb->len += slen;
if (dtb->len == 2) {
if (*dtb->data == '*') {
printf("%s\n", dtb->data);
dtb->front = dtb->data;
dtb->len = 0;
*dtb->data = '\0';
switch(*(dtb->data+1)) {
case '0':
dtb->fh.speed = 0;
break;
case '1':
dtb->fh.speed++;
break;
case '2':
dtb->fh.speed--;
break;
case '5':
{
switch_codec_t *codec = switch_core_session_get_read_codec(session);
samps = 5000 * (codec->implementation->samples_per_second / 1000);
switch_core_file_seek(&dtb->fh, &pos, samps, SEEK_CUR);
}
break;
case '4':
{
int32_t lpos = 0;
switch_codec_t *codec = switch_core_session_get_read_codec(session);
samps = 5000 * (codec->implementation->samples_per_second / 1000);
lpos = (int) dtb->fh.pos - samps;
if (lpos < 0) {
lpos = 0;
}
switch_core_file_seek(&dtb->fh, &pos, lpos, SEEK_SET);
}
break;
case '*':
if (switch_test_flag(&dtb->fh, SWITCH_FILE_PAUSE)) {
switch_clear_flag(&dtb->fh, SWITCH_FILE_PAUSE);
} else {
switch_set_flag(&dtb->fh, SWITCH_FILE_PAUSE);
}
break;
}
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_BREAK;
}
return SWITCH_STATUS_SUCCESS;
}
static void rss_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
uint8_t index = 0;
char fname[512];
switch_status_t status;
char buf[10];
struct dtmf_buffer dtb;
dtb.data = buf;
dtb.front = buf;
dtb.len = 0;
dtb.size = sizeof(buf);
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
if (switch_strlen_zero(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No Path Specified!\n");
return;
}
switch_channel_answer(channel);
while(switch_channel_ready(channel)) {
snprintf(fname, sizeof(fname), "%s/%.2u.raw", data, index);
memset(&dtb.fh, 0, sizeof(dtb.fh));
if ((status = switch_ivr_play_file(session, &dtb.fh, fname, NULL, on_dtmf, &dtb, sizeof(dtb))) == SWITCH_STATUS_FALSE) {
break;
}
index = atoi(buf);
/* reset for next loop */
*buf = '\0';
dtb.front = buf;
dtb.len = 0;
}
}
static const switch_application_interface_t rss_application_interface = {
/*.interface_name */ "rss",
/*.application_function */ rss_function,
NULL, NULL, NULL,
/*.next*/ NULL
};
static switch_loadable_module_interface_t rss_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ &rss_application_interface,
/*.api_interface */ NULL,
/*.file_interface */ NULL,
/*.speech_interface */ NULL,
/*.directory_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &rss_module_interface;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
/*
Called when the system shuts down
SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
{
return SWITCH_STATUS_SUCCESS;
}
*/
/*
If it exists, this is called in it's own thread when the module-load completes
SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
{
return SWITCH_STATUS_SUCCESS;
}
*/
......@@ -23,7 +23,7 @@ depends:
reswig:
rm switch_swig_wrap.c
swig -DMULTIPLICITY -perl5 -module fs_perl switch_swig.c
swig -lswitch_swig.i -ignoremissing -DMULTIPLICITY -perl5 -module fs_perl switch_swig.c
switch_swig_wrap.o: switch_swig_wrap.c
$(CC) -w $(CFLAGS) -c $< -o $@
......
......@@ -82,10 +82,10 @@ void fs_channel_pre_answer(switch_core_session_t *session)
switch_channel_pre_answer(channel);
}
void fs_channel_hangup(switch_core_session_t *session)
void fs_channel_hangup(switch_core_session_t *session, char *cause)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
switch_channel_hangup(channel, switch_channel_str2cause(cause));
}
void fs_channel_set_variable(switch_core_session_t *session, char *var, char *val)
......@@ -105,16 +105,17 @@ void fs_channel_set_state(switch_core_session_t *session, char *state)
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_state_t fs_state = switch_channel_get_state(channel);
if (!strcmp(state, "EXECUTE")) {
fs_state = CS_EXECUTE;
} else if (!strcmp(state, "TRANSMIT")) {
fs_state = CS_TRANSMIT;
if ((fs_state = switch_channel_name_state(state)) < CS_HANGUP) {
switch_channel_set_state(channel, fs_state);
}
switch_channel_set_state(channel, fs_state);
}
int fs_ivr_play_file(switch_core_session_t *session, char *file, char *timer_name)
int fs_ivr_play_file(switch_core_session_t *session,
char *file,
char *timer_name,
switch_dtmf_callback_function_t dtmf_callback,
void *buf,
unsigned int buflen)
{
switch_status_t status;
if (switch_strlen_zero(timer_name)) {
......
// gd.i
%module fs_perl
%{
#include <switch.h>
%}
// Grab the gd.h header file
%include <switch.h>
......@@ -370,7 +370,8 @@ static const char *state_names[] = {
"CS_LOOPBACK",
"CS_HOLD",
"CS_HANGUP",
"CS_DONE"
"CS_DONE",
NULL
};
SWITCH_DECLARE(const char *) switch_channel_state_name(switch_channel_state_t state)
......@@ -378,6 +379,19 @@ SWITCH_DECLARE(const char *) switch_channel_state_name(switch_channel_state_t st
return state_names[state];
}
SWITCH_DECLARE(switch_channel_state_t) switch_channel_name_state(char *name)
{
uint32_t x = 0;
for(x = 0; state_names[x]; x++) {
if (!strcasecmp(state_names[x], name)) {
return (switch_channel_state_t) x;
}
}
return CS_DONE;
}
SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_channel_t *channel,
const char *file,
const char *func,
......
......@@ -288,9 +288,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
file,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
switch_core_session_reset(session);
return SWITCH_STATUS_GENERR;
return SWITCH_STATUS_NOTFOUND;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论