flite_rename_voice 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. ###########################################################################
  3. ## ##
  4. ## Language Technologies Institute ##
  5. ## Carnegie Mellon University ##
  6. ## Copyright (c) 2010 ##
  7. ## All Rights Reserved. ##
  8. ## ##
  9. ## Permission is hereby granted, free of charge, to use and distribute ##
  10. ## this software and its documentation without restriction, including ##
  11. ## without limitation the rights to use, copy, modify, merge, publish, ##
  12. ## distribute, sublicense, and/or sell copies of this work, and to ##
  13. ## permit persons to whom this work is furnished to do so, subject to ##
  14. ## the following conditions: ##
  15. ## 1. The code must retain the above copyright notice, this list of ##
  16. ## conditions and the following disclaimer. ##
  17. ## 2. Any modifications must be clearly marked as such. ##
  18. ## 3. Original authors' names are not deleted. ##
  19. ## 4. The authors' names are not used to endorse or promote products ##
  20. ## derived from this software without specific prior written ##
  21. ## permission. ##
  22. ## ##
  23. ## CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK ##
  24. ## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ##
  25. ## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ##
  26. ## SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE ##
  27. ## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ##
  28. ## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ##
  29. ## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ##
  30. ## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ##
  31. ## THIS SOFTWARE. ##
  32. ## ##
  33. ###########################################################################
  34. #
  35. # Renames a clunits/voxdata flite voice build by build_flite
  36. #
  37. # flite_rename_voice FROMDIR NEWNAME TODIR
  38. #
  39. # You have to recompile it afterwards
  40. #
  41. FROMDIR=$1
  42. NEWNAME=$2
  43. TODIR=$3
  44. OLDNAME=`cat $FROMDIR/voxdefs.h | awk '{ if ($2 == "VOXNAME") printf("%s",$3)}'`
  45. mkdir -p $TODIR
  46. if [ ! -f $FROMDIR/$OLDNAME.c ]
  47. then
  48. echo Current directory does not contain $FROMDIR/$OLDNAME.c
  49. echo no renaming possible
  50. exit -1
  51. fi
  52. for i in $FROMDIR/*.c $FROMDIR/*.h $FROMDIR/Makefile
  53. do
  54. fname=`basename $i`
  55. cat $i |
  56. sed 's/'$OLDNAME'/'$NEWNAME'/g' |
  57. cat >$TODIR/`echo $fname | sed 's/'$OLDNAME'/'$NEWNAME'/g'`
  58. done
  59. for i in $FROMDIR/*.raw
  60. do
  61. fname=`basename $i`
  62. cp -p $i $TODIR/`echo $fname | sed 's/'$OLDNAME'/'$NEWNAME'/g'`
  63. done
  64. for i in $FROMDIR/*.voxdata
  65. do
  66. fname=`basename $i`
  67. echo $OLDNAME $NEWNAME |
  68. awk '{if (length($1) < length($2))
  69. {
  70. fo = sprintf("%%%ds",length($2));
  71. o = sprintf(fo,$1);
  72. n = $2;
  73. }
  74. else
  75. {
  76. fn = sprintf("%%%ds",length($1));
  77. n = sprintf(fn,$2);
  78. o = $1;
  79. }
  80. printf("#>%s<<%s<\n",n,o);
  81. printf("sed '"'"'s%%%s%%%s%%'"'"'\n",o,n)}' >$TODIR/sed.command
  82. sh $TODIR/sed.command <$i >$TODIR/`echo $fname | sed 's/'$OLDNAME'/'$NEWNAME'/g'`
  83. rm -f $TODIR/sed.command
  84. done