Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
543 views
in Technique[技术] by (71.8m points)

app-inventor - 当给定的消息太长时,App Inventor的TextToSpeech不起作用(App Inventor's TextToSpeech does not work when the given message is too long)

In MIT App Inventor, there is a media component called TextToSpeech .

(在MIT App Inventor中,有一个名为TextToSpeech的媒体组件。)

It has a method called Speak(text message) , which speaks a given message.

(它具有一种称为Speak(text message) ,该方法可以说出给定的消息。)

The problem I encounter is, when the given message is very long (eg, the text of Genesis chapter one, about 4260 characters), TextToSpeech does not speak at all.

(我遇到的问题是,当给定的消息很长时(例如,创世记第一章的文本,大约4260个字符),TextToSpeech根本不讲话。)

(And by the way, it works fine for Genesis chapter two, which is shorter, about 3164 characters.)

((顺便说一下,对于创世记第二章来说,它工作得很好,较短,大约3164个字符。))

  ask by Yuci translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The workaround (or mechanism) I have is to split the given message into a list of paragraphs by the new line character \n , (or into a list of sentences by the full stop character . if more appropriate in your case) and repeatedly call a procedure in which TextToSpeech is called to speak just a single paragraph.

(我必须采取的解决方法(或机制)是将给定消息用换行符\n拆分为段落列表(或如果使用句点字符.则用句号分隔句段),然后重复调用一个过程,其中调用TextToSpeech仅说单个段落。)

And in the event of TextToSpeech AfterSpeaking, check if there is more paragraph to speak;

(如果出现TextToSpeech AfterSpeaking,请检查是否还有更多要说的段落;)

if so, call the same procedure again.

(如果是这样,请再次调用相同的过程。)

This way, every time TextToSpeech.Speak is called, the given message is small enough for it to work properly.

(这样,每次调用TextToSpeech.Speak ,给定的消息就足够小以使其正常工作。)

Now there is no problem to speak a long message such as the text of Genesis chapter one.

(现在说长消息,如创世记第一章的文本,没有问题。)

See below the blocks:

(请参见下面的块:)

在此处输入图片说明

Note on the App Inventor version I'm working with:

(关于我正在使用的App Inventor版本的注意事项 :)

Built: November 26 2019 Version: nb180a
Use Companion: 2.55 or 2.55u or 2.55 or 2.55uu
Target Android SDK: 28 (Android 9.0 Pie)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...