t2p_main.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*************************************************************************/
  2. /* */
  3. /* Language Technologies Institute */
  4. /* Carnegie Mellon University */
  5. /* Copyright (c) 2001 */
  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. /* CARNEGIE MELLON UNIVERSITY 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 CARNEGIE MELLON UNIVERSITY 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 (awb@cs.cmu.edu) */
  34. /* Date: January 2001 */
  35. /*************************************************************************/
  36. /* */
  37. /* For text to phones */
  38. /* */
  39. /*************************************************************************/
  40. #include <stdio.h>
  41. #include <string.h>
  42. #include <sys/time.h>
  43. #include <unistd.h>
  44. #include "cst_args.h"
  45. #include "flite.h"
  46. #include "../lang/usenglish/usenglish.h"
  47. #include "../lang/cmulex/cmu_lex.h"
  48. static cst_voice *cmu_us_no_wave = NULL;
  49. static cst_utterance *no_wave_synth(cst_utterance *u)
  50. {
  51. return u;
  52. }
  53. static cst_voice *register_cmu_us_no_wave(const char *voxdir)
  54. {
  55. cst_voice *v = new_voice();
  56. cst_lexicon *lex;
  57. v->name = "no_wave_voice";
  58. /* Set up basic values for synthesizing with this voice */
  59. usenglish_init(v);
  60. feat_set_string(v->features,"name","cmu_us_no_wave");
  61. /* Lexicon */
  62. lex = cmu_lex_init();
  63. feat_set(v->features,"lexicon",lexicon_val(lex));
  64. /* Intonation */
  65. feat_set_float(v->features,"int_f0_target_mean",95.0);
  66. feat_set_float(v->features,"int_f0_target_stddev",11.0);
  67. feat_set_float(v->features,"duration_stretch",1.1);
  68. /* Post lexical rules */
  69. feat_set(v->features,"postlex_func",uttfunc_val(lex->postlex));
  70. /* Waveform synthesis: diphone_synth */
  71. feat_set(v->features,"wave_synth_func",uttfunc_val(&no_wave_synth));
  72. cmu_us_no_wave = v;
  73. return cmu_us_no_wave;
  74. }
  75. int main(int argc, char **argv)
  76. {
  77. cst_val *files;
  78. cst_features *args=new_features();
  79. cst_voice *v;
  80. cst_utterance *u;
  81. cst_item *s;
  82. const char *text, *name;
  83. files =
  84. cst_args(argv,argc,
  85. "usage: t2p \"word word word\"\n"
  86. "Convert text to US English phonemes.",
  87. args);
  88. if (files)
  89. text = val_string(val_car(files));
  90. else
  91. {
  92. fprintf(stderr,"no text specified\n");
  93. exit(-1);
  94. }
  95. flite_init();
  96. v = register_cmu_us_no_wave(NULL);
  97. u = flite_synth_text(text,v);
  98. for (s=relation_head(utt_relation(u,"Segment"));
  99. s;
  100. s = item_next(s))
  101. {
  102. name = item_feat_string(s,"name");
  103. printf("%s",name);
  104. /* If its a vowel and is stessed output stress value */
  105. if ((cst_streq("+",ffeature_string(s,"ph_vc"))) &&
  106. (cst_streq("1",ffeature_string(s,"R:SylStructure.parent.stress"))))
  107. printf("1");
  108. printf(" ");
  109. }
  110. printf("\n");
  111. delete_utterance(u);
  112. delete_features(args);
  113. delete_val(files);
  114. return 0;
  115. }