为什么TTS的SynthesisToFile永远将字符串保存到.wav?

时间:2018-11-24 23:04:43

标签: android text-to-speech

我正在尝试使用synthesisToFile将巨大的字符串(书页)保存到.wav文件,问题是保存完整文件需要11年。我什至把它分成几段,但仍然没有运气-

 ///
    Pattern re = Pattern.compile("[^.!?\\s][^.!?]*(?:[.!?](?!['\"]?\\s|$)[^.!?]*)*[.!?]?['\"]?(?=\\s|$)", Pattern.MULTILINE | Pattern.COMMENTS);
    Matcher reMatcher = re.matcher(charSequence);
    /////
    int position = 0;
    int sizeOfChar = charSequence.length();
    String testStri = charSequence.substring(position, sizeOfChar);
    while (reMatcher.find()) {
        String temp = "";
        try { // speak
            temp = testStri.substring(charSequence.lastIndexOf(reMatcher.group()), charSequence.indexOf(reMatcher.group()) + reMatcher.group().length());
            // save to wav
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                textToSpeech.synthesizeToFile(temp, null, new File(String.valueOf(path) + "/mm.mp3"), "speak");
            }
        } catch (Exception e) {
            // error
            break;
        }
    }

0 个答案:

没有答案