rss2ivr.pl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/perl
  2. ##########################################################################
  3. # rss2ivr.pl -- A Script to turn an RSS feed into audio files.
  4. #
  5. # Copyright (C) 2006-2012, Anthony Minessale
  6. #
  7. # Anthony Minessale <anthm@freeswitch.org>
  8. #
  9. # This program is free software, distributed under the terms of
  10. # Perl itself
  11. ##########################################################################
  12. use XML::RSS;
  13. require LWP::UserAgent;
  14. ################################################################################
  15. my $swift = "/opt/swift/bin/swift";
  16. ################################################################################
  17. my $rss = new XML::RSS;
  18. my $root = shift;
  19. my $target = shift;
  20. my $dir = shift;
  21. my $saytxt;
  22. my $voice = shift || "David";
  23. my $ua = LWP::UserAgent->new;
  24. $ua->timeout(10);
  25. unless($root and $target and $dir) {
  26. die("Usage: $0 <root dir> <target url> <ivr name>\n");
  27. }
  28. unless(-d $root) {
  29. mkdir($root);
  30. }
  31. chdir($root) or die("where is $root");
  32. if ($target =~ /http/) {
  33. my $response = $ua->get($target);
  34. if ($response->is_success) {
  35. $in = $response->content;
  36. } else {
  37. die $response->status_line;
  38. }
  39. my $x = 1;
  40. $rss->parse($in);
  41. system("rm -fr $$");
  42. mkdir($$);
  43. die unless(-d $$);
  44. chdir($$);
  45. open(I,">00.txt");
  46. print I "$dir main index.\n";
  47. foreach my $item (@{$rss->{'items'}}) {
  48. my $xx = sprintf("%0.2d", $x);
  49. my $title .= "entry $xx, " . $item->{'title'} . ".\n";
  50. print I $title;
  51. my $desc = $item->{'description'};
  52. $desc =~ s/\<[^\>]+\>//g;
  53. my $content = "entry $xx.\n" . $item->{'title'} . ".\n". $desc;
  54. open(X,">$xx.txt");
  55. $content =~ s/[^\w\d\s \.\,\-\n]//smg;
  56. print X $content;
  57. close X;
  58. 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";
  59. system $do;
  60. $x++;
  61. }
  62. 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";
  63. system $do;
  64. close(I);
  65. chdir("..");
  66. system("/bin/rm -fr $dir");
  67. system("/bin/mv -f $$ $dir");
  68. }