主要是在项目遇到了需要将ffmpeg+文本转语音的音视频剪辑时的问题,现在分享出来希望给正在写有关的语音的一些灵感 ,我是小白,大神勿喷
TtsService.java
package com.example.demo2.Service;
import com.google.gson.Gson;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.locks.ReentrantLock;
@Service
public class TtsService {
private static final String TTE = "UTF8";
private static final String VCN = "xiaoyan";
private static final String APP_ID = "eee1fe11";
private static final Gson gson = new Gson();
private WebSocketClient client;
public static boolean wsCloseFlag = false;
String outputFile = "src/main/resources/tts/" + System.currentTimeMillis() + ".mp3";
@Value("${speech.hostUrl}")
private String hostUrl;
@Value("${speech.apiKey}")
private String apiKey;
@Value("${speech.apiSecret}")
private String apiSecret;
public String synthesize(Stri