Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6029107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:50:15+00:00 2026-05-23T04:50:15+00:00

I am using a very basic java sound class to stream audio from Bing

  • 0

I am using a very basic java sound class to stream audio from Bing Translate for the pronounciation of Chinese characters. It’s worked wonderfully for all of the 20 words I’ve tested except one.

When I try to get the pronunciation for the word 你 (which means you), I get the wrong sound. The strange thing is, when I take the URL that’s formed in the code and manually put it into a browser (I’m using the Bing Translate HTTP API), I’m getting the correct sound. So it seems to me the error has to be somewhere in my code. The only place I can think of is the buffer.

The really strange thing is that I’m not getting silence or gibberish. Instead, the sound that’s coming back is the way to say “one half” (literally saying “one part of two”) in chinese. As I said before, when I put the URL into a browser I get the proper sound for “you.”

EDIT: Also, if I put 你们 (which is plural for you and includes the original character) I get the correct sound back.

My code is below. In my pvsm, all I have is creating an instance of this class and then calling speakWord(你)

    public class WordSpeaker {
    private static final String TEST_CONN = "http://api.microsofttranslator.com/v2/Http.svc/" +
            "Detect?appId=5768596A4F34453BDAED3138E800D4F7EB5097B9&text=hello";
    private static final String TEST_VAL = "en";

    private static final String URL_FRONT = "http://api.microsofttranslator.com/v2/Http.svc/Speak?appId=" +
            "5768596A4F34453BDAED3138E800D4F7EB5097B9" + "&text=";
    private static final String URL_END = "&language=zh-cn";

    private AudioInputStream audioStream = null;
    private static final int EXTERNAL_BUFFER_SIZE = 128000;


    public WordSpeaker() {

    }

    public void speakWord(String sWord) {
        try {
            URL bingTranslate = new URL(URL_FRONT + sWord + URL_END);
            System.out.println(bingTranslate.toString());
            audioStream = AudioSystem.getAudioInputStream(bingTranslate);
        } catch (Exception e) {
            e.printStackTrace();
        }

        AudioFormat format = audioStream.getFormat();
        SourceDataLine line = null;
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);

        try {
            line = (SourceDataLine) AudioSystem.getLine(info);
            line.open(format);
        } catch (LineUnavailableException le) {
            System.out.println(le);
        } catch (Exception e) {
            e.printStackTrace();
        }

        line.start();

        int bytesRead = 0;
        byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];

        while (bytesRead != -1){
            try{
                bytesRead = audioStream.read(abData,0,abData.length);
            } catch (Exception e){
                e.printStackTrace();
            }
            if (bytesRead >=0){
                int bytesWritten = line.write(abData,0,bytesRead);
            }
        }

        line.drain();
        line.close();

    }

    private boolean testBing() {
        try {
            URL test = new URL(TEST_CONN);
            BufferedReader testRead = new BufferedReader(new InputStreamReader(test.openStream()));

            String inLine = testRead.readLine();
            return inLine.substring(inLine.lastIndexOf("\">") + 2, inLine.lastIndexOf("<")).equals(TEST_VAL);

        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:50:16+00:00Added an answer on May 23, 2026 at 4:50 am

    So I finally, figured this out with some help from the microsoft translate forum. It turns out that since I’m using special characters the encoding does matter. It’s just strange how it worked for every single character except this one and this one still was able to produce some intelligible (albeit wrong) output.

    The following line needs to be changed from

    URL bingTranslate = new URL(URL_FRONT + sWord + URL_END);
    

    to

    URL bingTranslate = new URL(URL_FRONT + URLEncoder.encode(sWord, "UTF-8") + URL_END);
    

    I only stumbled upon this because my URLs were getting a malfored URL error from the server when I attempted to play sounds from my jar file while it worked perfectly in the IDE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a very basic web browser using JEditorPane just to teach myself
I have a very basic question about MVC web applications in Java. Since the
This is very basic question from programming point of view but as I am
I am very new at java and my be missing something very basic. When
I'm searching for a very basic PHP templating system. Right now I'm using: /**
We are using LINQ very widely in our system. Particularly LINQ-to-objects. So in some
I am using a very intrinsic database with a CakePHP application and so far
I have been using Hibernate very successfully, but today I noticed a bizarre phenomenon
Background I am writing and using a very simple CGI-based (Perl) content management tool
I still very new using Subversion. Is it possible to have a working copy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.