簡體   English   中英

Bing文字轉語音在Android中不起作用

[英]Bing text to speech not working in Android

因此,我克隆了示例Cognitive-Speech-TTS並測試了Android TTS,但無法正常工作,我聽不到任何結果/聲音,我已經完成了必要的要求,例如獲得API訂閱密鑰並對其進行管理。 所以這里的Logcat結果

com.microsoft.sdksample W/ResourceType: Found multiple library tables, ignoring...
com.microsoft.sdksample W/ResourceType: Found multiple library tables, ignoring...
com.microsoft.sdksample W/ResourceType: Found multiple library tables, ignoring...
com.microsoft.sdksample D/Authentication: new Access Token: ******************
com.microsoft.sdksample D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
com.microsoft.sdksample D/Atlas: Validating map...
com.microsoft.sdksample I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.01.00.042.030_msm8226_LA.BF.1.1.1_RB1__release_AU ()
                                                                     OpenGL ES Shader Compiler Version: E031.25.03.06
                                                                     Build Date: 06/10/15 Wed
                                                                     Local Branch: 
                                                                     Remote Branch: quic/LA.BF.1.1.1_rb1.24
                                                                     Local Patches: NONE
                                                                     Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.01.00.042.030 + 6151be1 +  NOTHING
com.microsoft.sdksample I/OpenGLRenderer: Initialized EGL, version 1.4
com.microsoft.sdksample D/OpenGLRenderer: Enabling debug mode 0
com.microsoft.sdksample I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@166d0b8f time:2397803

我通過使用XmlDom類獲取SSML解決了該問題

字符串正文= XmlDom.createDom(deviceLanguage,genderName,voiceName,“此處輸入文字”);

byte [] xmlBytes = body.getBytes();

urlConnection.setRequestProperty(“ content-length”,String.valueOf(xmlBytes.length));

public class XmlDom {
    public static String createDom(String locale, String genderName, String voiceName, String textToSynthesize){
        Document doc = null;
        Element speak, voice;
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = dbf.newDocumentBuilder();
            doc = builder.newDocument();
            if (doc != null){
                speak = doc.createElement("speak");
                speak.setAttribute("version", "1.0");
                speak.setAttribute("xml:lang", "en-us");
                voice = doc.createElement("voice");
                voice.setAttribute("xml:lang", locale);
                voice.setAttribute("xml:gender", genderName);
                voice.setAttribute("name", voiceName);                        voice.appendChild(doc.createTextNode(textToSynthesize));
                speak.appendChild(voice);
                doc.appendChild(speak);
            }
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return transformDom(doc);
    }

    private static String transformDom(Document doc){
        StringWriter writer = new StringWriter();
        try {
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer;
            transformer = tf.newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            transformer.transform(new DOMSource(doc), new StreamResult(writer));
        } catch (TransformerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return writer.getBuffer().toString().replaceAll("\n|\r", "");
    }
}

更新:

使用XmlDom類獲取SSML之后,我發現SSML需要在語音標簽中指定xml:lang ='YOU_LANGUAGE_HERE' 例如

<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='Female' name='Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)'>This is a demo of Microsoft Cognitive Services Text to Speech API.</voice></speak>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM