亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Android 的 Java 中使用 Microsoft Speech API 文本到語音?

在 Android 的 Java 中使用 Microsoft Speech API 文本到語音?

大話西游666 2022-11-02 15:05:45
我正在嘗試在我的 Android 的 java 項目中使用 Microsoft Speech API text-to-speech。它不工作。是否可以在 java 中使用此 API?語音轉文本工作正常,我找到了快速入門并且使用它沒有問題。但是,沒有用于文本到語音的 java 示例,僅在C#、C++ (Windows)和C++ (Linux)中。我試圖在java中調整代碼,但它不起作用,我不知道為什么。 public void onTextToSpeechButtonClicked(View v) {        TextView txt = (TextView) this.findViewById(R.id.texttospeech); // 'texttospeech' is the ID of my text view        try {            // THIS LINE ISN'T WORKING            com.microsoft.cognitiveservices.speech.internal.SpeechConfig config = com.microsoft.cognitiveservices.speech.internal.SpeechConfig.FromSubscription(speechSubscriptionKey, serviceRegion);             config.SetSpeechRecognitionLanguage("fr-FR");            assert(config != null);            // Creates a speech synthesizer using the default speaker as audio output            SpeechSynthesizer synthesizer = SpeechSynthesizer.FromConfig(config);            assert(synthesizer != null);            SpeechSynthesizer synthesizer1 = SpeechSynthesizer.FromConfig(config);            SpeechSynthesisResult result = synthesizer.SpeakTextAsync(txt.toString()).Get();            // Checks result            if (result.getReason().equals(ResultReason.SynthesizingAudioCompleted)){                txt.setText("The text has been said.");            }            else if (result.getReason().equals(ResultReason.Canceled)){                SpeechSynthesisCancellationDetails cancellation = SpeechSynthesisCancellationDetails.FromResult(result);                txt.setText("CANCELED: Reason ="+cancellation.getReason());                if(cancellation.getReason().equals(CancellationReason.Error)){                    txt.append("ErrorCode = "+cancellation.getErrorCode()+" / ErrorDetails = "+cancellation.getErrorDetails()+" / Did you update the subscription info ?");                }            }            synthesizer.delete();        } catch (Exception ex) {            Log.e("SpeechSDKDemo", "unexpected " + ex.getMessage());            assert(false);        }    }有人能幫我嗎?
查看完整描述

2 回答

?
蕭十郎

TA貢獻1815條經驗 獲得超13個贊

我搜索了 Microsoft Speech API 是否與 Java 兼容,答案是否定的。這似乎也有點明顯,因為 Microsoft = C++ / C# 這與 Java 一點也不相似。此外,在您的帖子中,您提到了快速入門。這使用認知服務語音 SDK 而不是 Microsoft SAPI。

但是,有一些本地 Java 庫允許 Text-To-Speech。這是一篇與文本轉語音引擎相關的帖子。這是有關它的更多信息。也有適用于 Android 的庫:


查看完整回答
反對 回復 2022-11-02
?
慕沐林林

TA貢獻2016條經驗 獲得超9個贊

我會建議一個替代方案。為什么不嘗試使用 windows tts,而是將文本發送到可以從 java 代碼執行的 powershell 命令:


 String[] command = {"powershell.exe", "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('" + message +"');"};

 try {

        ProcessBuilder pb = new ProcessBuilder(command);

        Process process = pb.start();

        System.out.format("Process exit code: %d", process.waitFor());

        ProcessInputOutput.readStdnOutput(process);

    }

    catch (Exception e){

        e.printStackTrace();

    }


查看完整回答
反對 回復 2022-11-02
  • 2 回答
  • 0 關注
  • 198 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號