home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / fest-141.zip / festival / examples / latest.sh < prev    next >
Text File  |  1999-09-09  |  5KB  |  116 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-*-mode:scheme-*-
  2. ;;                                                                       ;;
  3. ;;                Centre for Speech Technology Research                  ;;
  4. ;;                     University of Edinburgh, UK                       ;;
  5. ;;                       Copyright (c) 1996,1997                         ;;
  6. ;;                        All Rights Reserved.                           ;;
  7. ;;                                                                       ;;
  8. ;;  Permission is hereby granted, free of charge, to use and distribute  ;;
  9. ;;  this software and its documentation without restriction, including   ;;
  10. ;;  without limitation the rights to use, copy, modify, merge, publish,  ;;
  11. ;;  distribute, sublicense, and/or sell copies of this work, and to      ;;
  12. ;;  permit persons to whom this work is furnished to do so, subject to   ;;
  13. ;;  the following conditions:                                            ;;
  14. ;;   1. The code must retain the above copyright notice, this list of    ;;
  15. ;;      conditions and the following disclaimer.                         ;;
  16. ;;   2. Any modifications must be clearly marked as such.                ;;
  17. ;;   3. Original authors' names are not deleted.                         ;;
  18. ;;   4. The authors' names are not used to endorse or promote products   ;;
  19. ;;      derived from this software without specific prior written        ;;
  20. ;;      permission.                                                      ;;
  21. ;;                                                                       ;;
  22. ;;  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        ;;
  23. ;;  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      ;;
  24. ;;  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   ;;
  25. ;;  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     ;;
  26. ;;  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    ;;
  27. ;;  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   ;;
  28. ;;  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          ;;
  29. ;;  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       ;;
  30. ;;  THIS SOFTWARE.                                                       ;;
  31. ;;                                                                       ;;
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33. ;;;           Author:  Alan W Black
  34. ;;;           Date:    September 1996
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ;;;
  37. ;;;  Gets the a summary of the latest news from Pathfinder.com (Time
  38. ;;;  magazine and synthesizes it).  My first web based speech application.
  39. ;;;
  40. ;;;  This is far too dependent on Time's latest news pages format and
  41. ;;;  not really very general, but its a start.  Also they seem to change
  42. ;;;  both the format and the name of the pages regularly so this probably
  43. ;;;  no longer works.
  44. ;;;
  45. ;;;  Note the news in Copyright Reuters, and should not be used except
  46. ;;;  for personal use.  This program can be viewed simply as a web
  47. ;;;  browser (for one particular page) and does not itself contain any
  48. ;;;  information under Time or Reuter copyright.
  49. ;;;
  50.  
  51. ;;; Because this is a --script type file I has to explicitly
  52. ;;; load the initfiles: init.scm and user's .festivalrc
  53. (load (path-append libdir "init.scm"))
  54.  
  55. (audio_mode 'async)  ;; play waves while continuing synthesis
  56.  
  57. ;;; Give short introduction, so something can happen while we're 
  58. ;;; getting the news
  59. (SayText "And here is the news.")
  60. (SayText "News stories are courtesy of Time Warners' Path finder Magazine
  61.           and Reuters News Media.")
  62.  
  63. (format t "Getting news from Pathfinder Magazine ... \n")
  64. (fflush nil)
  65. ;;;  First get the page
  66.  
  67. (set! tmpfile (make_tmp_filename))
  68. (set! tmpfile2 (string-append tmpfile "_2"))
  69.  
  70. (get_url "http://www.pathfinder.com/news/latest" tmpfile)
  71.  
  72. (format t "done\n")
  73.  
  74. ;; This has to be powerful awk, not the original awk.  GNU awk or nawk
  75. ;; are what I'm looking for, but they have such random names, and may or
  76. ;; may not be on your system.
  77. (if (string-matches *ostype* ".*Linux.*")
  78.     (defvar GOOD_AWK "awk")
  79.     (defvar GOOD_AWK "nawk"))
  80.  
  81. ;; Should now use some HTML to SSML conversion but hack it just now
  82. (system 
  83.  (string-append
  84.   GOOD_AWK " '{ if ($1 == \"<dl>\")
  85.     inlist = 1;
  86.        if (inlist == 1)
  87.        {
  88.           if ($1 == \"<dt>\")   # title
  89.       {
  90.            getline  # skip href
  91.            getline
  92.            line = $0
  93.            sub(/^.*<b>/,\"\",line);
  94.            sub(/ *<.b>.*$/,\"\",line);
  95.                printf(\"%s, \",line);
  96.           }
  97.           else if ($1 == \"<dd>\") # summary
  98.           {
  99.                getline
  100.                line = $0
  101.                sub(/\(.. ... .... ..:.. ...\)/,\"\",line) # remove time stamp
  102.                printf(\"%s\\n\\n\",line);
  103.           }
  104.           else if ($1 == \"</dl>\")
  105.                inlist = 0;
  106.        }
  107.      }' < " tmpfile " > " tmpfile2))
  108.  
  109. ;;  Say the news
  110. (tts_file tmpfile2 nil)
  111.  
  112. (system (string-append "rm -f " tmpfile " " tmpfile2))
  113. (audio_mode 'close)  ;; close gracefully
  114.  
  115.  
  116.