/text_reader.php

https://github.com/atutor/atalker · PHP · 103 lines · 83 code · 5 blank · 15 comment · 3 complexity · e328876ee2cbf734ca3398bfd8b3fe4b MD5 · raw file

  1. <?php
  2. /****************************************************************/
  3. /* ATalker */
  4. /****************************************************************/
  5. /* Copyright (c) 2002-2005 by Greg Gay */
  6. /* Adaptive Technology Resource Centre / University of Toronto */
  7. /* http://atutor.ca */
  8. /* */
  9. /* This program is free software. You can redistribute it and/or*/
  10. /* modify it under the terms of the GNU General Public License */
  11. /* as published by the Free Software Foundation. */
  12. /****************************************************************/
  13. // $Id: text_reader.php 5123 2005-07-12 14:59:03Z greg $
  14. // Get the time to use as a default filename
  15. $now = time();
  16. // Otherwise use the file name entered by the user
  17. if($_POST['filename']){
  18. if($_SESSION['course_id'] > 0){
  19. $file_save = AT_SPEECH_FILES_DIR.$_POST['filename'];
  20. }else{
  21. $file_save = AT_SPEECH_TEMPLATE_DIR.$_POST['filename'];
  22. }
  23. }else{
  24. if($_SESSION['course_id'] > 0){
  25. $file_save = AT_SPEECH_FILES_DIR.$now.'.'.$_POST['file_type'];
  26. }else{
  27. $file_save = AT_SPEECH_TEMPLATE_DIR.$now.'.'.$_POST['file_type'];
  28. }
  29. }
  30. $file_out = AT_SPEECH_DIR.'/'.$now.'.wav';
  31. $file_out_mp3 = AT_SPEECH_DIR.$now.'.mp3';
  32. $file_out_ogg = AT_SPEECH_DIR.$now.'.ogg';
  33. $file_in = AT_SPEECH_DIR.$now.'.txt';
  34. $file_recieve = AT_SPEECH_URL.$now.'.'.$_POST['file_type'];
  35. $scheme_out = AT_SPEECH_DIR.$now.'.scm';
  36. // Build the Scheme file. Lots more can be done here to customize voices
  37. $scheme_in .= "(";
  38. $scheme_in .= $_POST['voice'];
  39. $scheme_in .= ")\n";
  40. $scheme_in .= "(";
  41. $scheme_in .= "Parameter.set 'Duration_Stretch ".$_POST['duration'];
  42. $scheme_in .= ")";
  43. // create a scheme file with the voice properties
  44. $fp = fopen($scheme_out,'w');
  45. if (!$fp) {
  46. echo AT_ERROR_TTS_NOT_CREATE_SCHEME;
  47. exit;
  48. }
  49. fputs($fp, $scheme_in);
  50. fclose($fp);
  51. //$file_props = "-mode --tts -eval ".AT_SPEECH_DIR.$now.".scm";
  52. if(!$_POST['create'] && !$_POST['remove']){
  53. //create a text file from the inputted text
  54. $fp = fopen($file_in,'w');
  55. if (!$fp) {
  56. echo AT_ERROR_TTS_NOT_CREATE_TEXT;
  57. exit;
  58. }
  59. fputs($fp, $_POST['textin']);
  60. fclose($fp);
  61. if($_POST['file_type'] == "mp3"){
  62. $command = "text2wave $file_props $file_in -o $file_out -F 48000 -scale ".$_POST['volumn']."";
  63. if(shell_exec('lame --longhelp')){
  64. $command2 = 'lame --quiet '.$file_out.' '. $file_out_mp3;
  65. }else if (shell_exec('bladeenc -h')) {
  66. $command2 = 'bladeenc -quiet '.$file_out.' '. $file_out_mp3;
  67. }
  68. escapeshellcmd($command);
  69. escapeshellcmd($command2);
  70. passthru($command);
  71. passthru($command2);
  72. gen_tts();
  73. }else if($_POST['file_type'] == "ogg"){
  74. $command = "text2wave $file_props $file_in -o $file_out -F 48000 -scale ".$_POST['volumn']."";
  75. $command2 = 'oggenc -quiet '.$file_out.' '. $file_out_ogg;
  76. escapeshellcmd($command);
  77. escapeshellcmd($command2);
  78. passthru($command);
  79. passthru($command2);
  80. gen_tts();
  81. }else{
  82. $command = "text2wave $file_props $file_in -o $file_out -F 48000 -scale ".$_POST['volumn']."";
  83. escapeshellcmd($command);
  84. passthru($command);
  85. gen_tts();
  86. }
  87. }
  88. ?>