draft : text to speed , offline code.in java(key) instead of pyton, reason why pyton (not asking subkey), where java asks?

 

//not testing, for java it is asking subscription key.

import org.apache.http.client.methods.HttpPost;

import org.apache.http.entity.StringEntity;

import org.apache.http.impl.client.CloseableHttpClient;

import org.apache.http.impl.client.HttpClients;

import org.apache.http.HttpResponse;

import org.apache.http.util.EntityUtils;

import org.json.JSONObject;


import javax.sound.sampled.*;

import java.io.*;

import java.nio.file.*;

import java.util.ArrayList;

import java.util.List;


public class TextToSpeechEdgeTTS {


    static final String INPUT_FILE = "input.txt";

    static final String VOICE = "te-IN-ShrutiNeural";

    static final int CHUNK_SIZE = 4000;

    static final String TEMP_DIR = "temp_chunks";

    static final String FINAL_MP3 = "output.mp3";


    public static void main(String[] args) throws Exception {

        String text = readText(INPUT_FILE);

        if (text.isEmpty()) return;


        List<String> chunks = chunkText(text, CHUNK_SIZE);

        new File(TEMP_DIR).mkdirs();


        List<File> chunkFiles = new ArrayList<>();

        int idx = 0;

        for (String chunk : chunks) {

            String rate = mapSpeedToRate(5);  // set desired speed 1–7

            File chunkFile = new File(TEMP_DIR + "/chunk_" + idx + ".mp3");

            generateChunk(chunk, chunkFile, VOICE, rate);

            chunkFiles.add(chunkFile);

            System.out.println("Generated chunk: " + chunkFile.getName());

            idx++;

        }


        mergeAudioFiles(chunkFiles, FINAL_MP3);

        System.out.println("✅ Final audio saved to: " + FINAL_MP3);

        cleanup();

    }


    static String readText(String path) throws IOException {

        return new String(Files.readAllBytes(Paths.get(path))).replaceAll("\\s+", " ");

    }


    static List<String> chunkText(String text, int maxLength) {

        List<String> chunks = new ArrayList<>();

        while (!text.isEmpty()) {

            if (text.length() <= maxLength) {

                chunks.add(text);

                break;

            }

            int splitAt = text.lastIndexOf(' ', maxLength);

            if (splitAt == -1) splitAt = maxLength;

            chunks.add(text.substring(0, splitAt));

            text = text.substring(splitAt).trim();

        }

        return chunks;

    }


    static String mapSpeedToRate(int value) {

        return switch (value) {

            case 1 -> "-75%";

            case 2 -> "-50%";

            case 3 -> "0%";

            case 4 -> "+25%";

            case 5 -> "+50%";

            case 6 -> "+75%";

            case 7 -> "+100%";

            default -> "0%";

        };

    }


    static void generateChunk(String text, File outputFile, String voice, String rate) throws Exception {

        String ssml = "<speak version='1.0' xml:lang='te-IN'>" +

                      "<prosody rate='" + rate + "'>" + escapeXml(text) + "</prosody></speak>";


        String tokenUrl = "https://eastus.tts.speech.microsoft.com/cognitiveservices/v1";


        HttpPost post = new HttpPost(tokenUrl);

        post.setHeader("Content-Type", "application/ssml+xml");

        post.setHeader("X-Microsoft-OutputFormat", "audio-16khz-128kbitrate-mono-mp3");

        post.setHeader("User-Agent", "JavaEdgeTTS");

        post.setHeader("Ocp-Apim-Subscription-Key", "YOUR_SUBSCRIPTION_KEY");  // 🔑 Replace with valid Azure key


        post.setEntity(new StringEntity(ssml));

        try (CloseableHttpClient client = HttpClients.createDefault()) {

            HttpResponse response = client.execute(post);

            byte[] audioBytes = EntityUtils.toByteArray(response.getEntity());

            Files.write(outputFile.toPath(), audioBytes);

        }

    }


    static String escapeXml(String s) {

        return s.replace("&", "&amp;").replace("<", "&lt;")

                .replace(">", "&gt;").replace("\"", "&quot;").replace("'", "&apos;");

    }


    static void mergeAudioFiles(List<File> inputFiles, String outputFile) throws IOException {

        try (FileOutputStream fos = new FileOutputStream(outputFile)) {

            for (File file : inputFiles) {

                Files.copy(file.toPath(), fos);

            }

        }

    }


    static void cleanup() throws IOException {

        for (File file : new File(TEMP_DIR).listFiles()) {

            file.delete();

        }

        new File(TEMP_DIR).delete();

        System.out.println("🧹 Temp files cleaned up.");

    }

}

🔑 Important Note:

To make the above code work:


You must have a valid Microsoft Azure TTS Subscription Key


You can get it from: https://portal.azure.com > Create a Cognitive Services > Speech


Replace this line with your actual key:


java

Copy

Edit

post.setHeader("Ocp-Apim-Subscription-Key", "YOUR_SUBSCRIPTION_KEY");

Would you like a downloadable ZIP with:


All required .jar files


A working Eclipse project with this code?


Or do you prefer converting this into a Maven-based project for better dependency management?







You said:

httpclient-4.5.13.jar, httpcore-4.4.13.jar download links for these two



ChatGPT said:

You're giving feedback on a new version of ChatGPT.

Which response do you prefer? Responses may take a moment to load.

ChatGPT

Response 1

Here are the official Maven Central download links for the JAR files:


✅ Apache HttpClient 4.5.13

JAR Download:

httpclient-4.5.13.jar


✅ Apache HttpCore 4.4.13

JAR Download:

httpcore-4.4.13.jar


⚠️ Note:

httpclient depends on httpcore, so both are required.

----------

Why Python code using edge-tts doesn't need a subscription key, but Java does:


🔹 Python Code Uses edge-tts (Unofficial Microsoft Edge TTS API Wrapper)

  • The Python edge-tts library uses undocumented internal endpoints used by the Microsoft Edge browser.

  • It mimics browser behavior and sends requests to Edge's public endpoints that do not require authentication or an API key.

  • This works because Microsoft exposes some TTS capabilities directly for Edge users — it’s free, fast, and doesn’t require any API token.

🔒 But: This is unofficial and may stop working if Microsoft changes their internal APIs.


🔹 Java Code Uses Microsoft Azure Cognitive Services

  • The Java approach uses the official Microsoft Azure Speech Service.

  • This service is secure and enterprise-grade, and thus requires:

    • Subscription key

    • Region endpoint

  • Authentication ensures Microsoft tracks usage, enforces quotas, and prevents abuse.


📊 Summary:

FeaturePython (edge-tts)Java (Azure SDK)
Uses official API❌ No✅ Yes
Requires subscription key❌ No✅ Yes
Free quota/limit control❌ None guaranteed✅ With Azure portal settings
Reliability⚠️ May break anytime✅ Stable, backed by Azure

Would you prefer switching to Python for ease or want help registering a free Azure TTS subscription key for Java use?

You said:
NBCU client, from this client i got one requirement saying 38L fixed and remote work, as of now working in ibm, 24L somehow i managing work remote? asking me 45days joining..
ChatGPT said:

That’s a significant jump, both in salary and in work flexibility. Let’s break it down so you can assess it clearly.


📊 Current vs. New Offer Overview

CategoryIBM (Current)NBCU (Offer)
CTC₹24 LPA₹38 LPA (Fixed)
Work ModeRemote (unofficially managed)Official Remote
Joining Notice-45 days (requested)
EmployerIBMNBCUniversal (NBCU)

Pros of NBCU Offer

  • ~58% hike in fixed pay — very strong.

  • Official remote: removes the stress of hiding or bending rules.

  • Likely better international exposure, given NBCU's global presence.

  • Could improve work-life balance, assuming team culture supports it.


⚠️ Things to Consider

  • Joining Timeline: If IBM enforces a 90-day notice, will NBCU flex the 45-day requirement?

  • Buyout Option: Can NBCU buy out your remaining notice if IBM won't relieve early?

  • Team Fit: Is the NBCU team technically strong, collaborative, and aligned with your goals?

  • Contract/Employment Type: Confirm it's permanent (not via a vendor or third-party).


💬 Suggested Next Steps

  1. Negotiate notice period with NBCU — share IBM’s policy and see if they can accept a 60-day join or help with buyout.

  2. Ask for offer letter and ensure:

    • Fixed vs. variable clearly mentioned.

    • Remote clause mentioned.

    • Onboarding process and team structure are clear.

  3. If comfortable, resign from IBM only after NBCU documentation is firm.

Also make sure you include commons-logging-1.2.jar if not already added.


Would you like me to prepare a .zip file with all 3 JARs bundled for Eclipse or a Maven project setup?

Popular posts from this blog

SAP CPI : camle expression in sap cpi , cm, router, filter and groovy script. format

pss book: గురు ప్రార్థనామంజరి . completed 21st july 2024

pss book : శ్రీకృష్ణుడు దేవుడా, భగవంతుడా completed , second review needed. 26th April 2024