5

でsynthesizeToFileながら、時間がかかりすぎます。テキスト読み上げは、私がビルトイン<strong><code>TTS Engine</code></strong>アンドロイドを使用して<strong><code>.mp3</code></strong>ファイルに<strong><code>.txt</code></strong>ファイルを合成するためのコードの下に使用しているAndroidの

コード:上記

textToSpeech.synthesizeToFile(readFileText, utterParam, destinationFileName); 

textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() { 
       @Override 
       public void onStart(final String utteranceId) { 
        Log.e(TAG, "onStart..."); 
       } 

       @Override 
       public void onDone(final String utteranceId) { 
        Log.e(TAG, "onDone..."); 
       } 

       @Override 
       public void onError(String utteranceId) { 
        Log.e(TAG, "onError..."); 
       } 
      }); 

は、サンプルコードです。ファイルの合成にのみ、その後に行われた場合:

  1. 発行mp3ファイルを再生

  • mp3にSDカードから
  • 合成ファイルをファイルを取得します。ここで は、アプリケーション実行の流れがあります私はmp3ファイルを再生することができます。サイズが1Mbの偶数ファイルの場合、約1分かかります。

    何か改善がありますか?

    注:リーダーを再生/一時停止する必要があるため、MediaPlayerを使用する必要があります。

    ありがとうございました。

  • +0

    役に立つと思われるリンク[android-sdk-to-speech-engine](http://code.tutsplus.com/tutorials/android-sdk-using-the-text-to-speech -engine - mobile-8540) –

    +1

    スピーチより合成が速いのですか?はいの場合は、合成して小さな塊で再生してみませんか?最初のMP3ファイルが作成され、より早く再生できる状態になります。他のチャンクがバックグラウンドで十分に高速に処理できる場合、前のファイルが再生されたときに再生を待つ準備ができています。 –

    +0

    再生を一時停止する必要があるため、発言を「話す」前に合成する必要があるのはなぜですか?合成しようとしている文字は何文字ですか?エンジンには受け入れ可能な数に制限があります。これはエンジンごとに異なります。出力はmp3でないwav/pcmです - あなたはこれを何らかの変換で実行していますか?これはファイルのラベル付け方法のエラーですか? – brandall

    答えて

    3

    この問題は、ファイル全体を段落に変換し、段落をTTSエンジンに追加して直接再生するという問題を解決しました。

    public static String[] convertFileToParagraph(String fileContent) { 
    
    //  String pattern = "(?<=(rn|r|n))([ \t]*$)+"; 
         String pattern = "([ \\t\\r]*\\n[ \\t\\r]*)+"; 
         return Pattern.compile(pattern, Pattern.MULTILINE).split(fileContent); 
        } 
    
    /** 
        * Divides files in to paragraphs 
        */ 
        private void divideFileToChunks() { 
         try { 
          currentFileChunks = convertFileToParagraph(fileContent); 
          currentFileChunks = makeSmallChunks(currentFileChunks); 
          addChunksToTTS(); 
         } catch (Exception e) { 
          e.printStackTrace(); 
         } 
        } 
    
        /** 
        * Divides file paragraphs into sentences of 200 characters 
        * 
        * @param currentFileChunks : list of paragraphs 
        * @return : list of divided file 
        */ 
        private String[] makeSmallChunks(String[] currentFileChunks) { 
         try { 
          ArrayList<String> smallChunks = new ArrayList<>(); 
          for (int i = 0; i < currentFileChunks.length; i++) { 
           String chunk = currentFileChunks[i]; 
           if (chunk != null && chunk.length() > 200) { 
            int length = chunk.length(); 
            int count = length/200; 
            int modulo = length % 200; 
            for (int j = 0; j < count; j++) { 
             smallChunks.add(chunk.substring(200 * j, (200 * j) + 199)); 
            } 
            if (modulo > 0) { 
             smallChunks.add(chunk.substring(chunk.length() - 1 - modulo, chunk.length() - 1)); 
            } 
           } else { 
            smallChunks.add(chunk); 
           } 
          } 
          return smallChunks.toArray(new String[smallChunks.size()]); 
         } catch (Exception e) { 
          e.printStackTrace(); 
          return currentFileChunks; 
         } 
        } 
    
        /** 
        * Add all chunks to TTS(Text to Speech) Engine 
        */ 
        private void addChunksToTTS() { 
         try { 
          String[] chunks = getCurrentFileChunks(); 
          if (chunks != null && chunks.length > 0) { 
           for (int i = currentChunk; i < chunks.length; i++) { 
            utterParam.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, String.valueOf(i)); 
            textToSpeech.speak(chunks[i], TextToSpeech.QUEUE_ADD, utterParam); 
            imgBtnT2SPlay.setImageResource(R.drawable.icon_pause_white); 
            edtT2SFileContents.setEnabled(false); 
            isPlaying = true; 
           } 
          } 
    
          if (progressDialog != null && progressDialog.isShowing()) { 
           progressDialog.dismiss(); 
          } 
         } catch (Exception e) { 
          e.printStackTrace(); 
         } 
        } 
    

    ありがとうございます。

    +0

    getCurrentFileChunks()メソッドも追加してください – Ragini

    関連する問題