Commit 4c433f5e by 苗权威

0114

parent d96bf9ea
package ai.qiwu.com.tts_service.common;
import ai.qiwu.com.tts_service.common.sound.SampleRateConverter;
import ai.qiwu.com.tts_service.pojo.TTSRequest;
import ai.qiwu.com.tts_service.service.Initialize;
import ai.qiwu.com.tts_service.service.TTService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.util.DigestUtils;
import javax.sound.sampled.AudioFileFormat;
......@@ -18,7 +12,6 @@ import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.*;
import java.nio.channels.FileLock;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
......
package ai.qiwu.com.tts_service.common.pcm;
/**
* 构建wav文件的头数据
* @author 苗权威
* @dateTime 19-8-14 下午2:20
*/
public class WavFileHeader {
/**
* RIFF数据块
*/
final String riffChunkId = "RIFF";
int riffChunkSize;
final String riffType = "WAVE";
/**
* FORMAT 数据块
*/
final String formatChunkId = "fmt ";
final int formatChunkSize = 16;
final short audioFormat = 1;
short channels;
int sampleRate;
int byteRate;
short blockAlign;
short sampleBits;
/**
* FORMAT 数据块
*/
final String dataChunkId = "data";
int dataChunkSize;
WavFileHeader(int totalAudioLen, int sampleRate, short channels, short sampleBits) {
this.riffChunkSize = totalAudioLen;
this.channels = channels;
this.sampleRate = sampleRate;
this.byteRate = sampleRate * sampleBits / 8 * channels;
this.blockAlign = (short) (channels * sampleBits / 8);
this.sampleBits = sampleBits;
this.dataChunkSize = totalAudioLen - 44;
}
public byte[] getHeader() {
byte[] result;
result = ByteUtils.merger(ByteUtils.toBytes(riffChunkId), ByteUtils.toBytes(riffChunkSize));
result = ByteUtils.merger(result, ByteUtils.toBytes(riffType));
result = ByteUtils.merger(result, ByteUtils.toBytes(formatChunkId));
result = ByteUtils.merger(result, ByteUtils.toBytes(formatChunkSize));
result = ByteUtils.merger(result, ByteUtils.toBytes(audioFormat));
result = ByteUtils.merger(result, ByteUtils.toBytes(channels));
result = ByteUtils.merger(result, ByteUtils.toBytes(sampleRate));
result = ByteUtils.merger(result, ByteUtils.toBytes(byteRate));
result = ByteUtils.merger(result, ByteUtils.toBytes(blockAlign));
result = ByteUtils.merger(result, ByteUtils.toBytes(sampleBits));
result = ByteUtils.merger(result, ByteUtils.toBytes(dataChunkId));
result = ByteUtils.merger(result, ByteUtils.toBytes(dataChunkSize));
return result;
}
}
package ai.qiwu.com.tts_service.common.pcm;
import lombok.Setter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* 获取wav文件的头数据
* @author 苗权威
* @dateTime 19-8-14 下午12:16
*/
@Setter
public class WavHeader {
private final char fileID[] = {'R', 'I', 'F', 'F'};
private int fileLength;
private char wavTag[] = {'W', 'A', 'V', 'E'};;
private char FmtHdrID[] = {'f', 'm', 't', ' '};
private int FmtHdrLeth;
private short FormatTag;
private short Channels;
private int SamplesPerSec;
private int AvgBytesPerSec;
private short BlockAlign;
private short BitsPerSample;
private char DataHdrID[] = {'d','a','t','a'};
private int DataHdrLeth;
public WavHeader() {
}
public WavHeader(int fileLength, int fmtHdrLeth, short formatTag, short channels,
int samplesPerSec, int avgBytesPerSec, short blockAlign, short bitsPerSample, int dataHdrLeth) {
this.fileLength = fileLength;
FmtHdrLeth = fmtHdrLeth;
FormatTag = formatTag;
Channels = channels;
SamplesPerSec = samplesPerSec;
AvgBytesPerSec = avgBytesPerSec;
BlockAlign = blockAlign;
BitsPerSample = bitsPerSample;
DataHdrLeth = dataHdrLeth;
}
public byte[] getHeader() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
WriteChar(bos, fileID);
WriteInt(bos, fileLength);
WriteChar(bos, wavTag);
WriteChar(bos, FmtHdrID);
WriteInt(bos,FmtHdrLeth);
WriteShort(bos,FormatTag);
WriteShort(bos,Channels);
WriteInt(bos,SamplesPerSec);
WriteInt(bos,AvgBytesPerSec);
WriteShort(bos,BlockAlign);
WriteShort(bos,BitsPerSample);
WriteChar(bos,DataHdrID);
WriteInt(bos,DataHdrLeth);
bos.flush();
byte[] r = bos.toByteArray();
bos.close();
return r;
}
private void WriteShort(ByteArrayOutputStream bos, int s) throws IOException {
byte[] mybyte = new byte[2];
mybyte[1] =(byte)( (s << 16) >> 24 );
mybyte[0] =(byte)( (s << 24) >> 24 );
bos.write(mybyte);
}
private void WriteInt(ByteArrayOutputStream bos, int n) throws IOException {
byte[] buf = new byte[4];
buf[3] =(byte)( n >> 24 );
buf[2] =(byte)( (n << 8) >> 24 );
buf[1] =(byte)( (n << 16) >> 24 );
buf[0] =(byte)( (n << 24) >> 24 );
bos.write(buf);
}
private void WriteChar(ByteArrayOutputStream bos, char[] id) {
for (char c : id) {
bos.write(c);
}
}
}
package ai.qiwu.com.tts_service.common.pcm;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.RandomAccessFile;
/**
* 封装的生成wav文件的工具类
*/
@Slf4j
public class WavUtils {
private static final String TAG = WavUtils.class.getSimpleName();
/**
* 生成wav格式的Header
* wave是RIFF文件结构,每一部分为一个chunk,其中有RIFF WAVE chunk,
* FMT Chunk,Fact chunk(可选),Data chunk
*
* @param totalAudioLen 不包括header的音频数据总长度
* @param sampleRate 采样率,也就是录制时使用的频率
* @param channels audioRecord的频道数量
* @param sampleBits 位宽
*/
public static byte[] generateWavFileHeader(int totalAudioLen, int sampleRate, int channels, int sampleBits) {
WavFileHeader wavHeader = new WavFileHeader(totalAudioLen, sampleRate, (short) channels, (short) sampleBits);
return wavHeader.getHeader();
}
/**
* 将header写入到pcm文件中 不修改文件名
*
* @param file 写入的pcm文件
* @param header wav头数据
*/
public static void writeHeader(File file, byte[] header) {
if (!file.isFile()) {
return;
}
try (RandomAccessFile wavRaf = new RandomAccessFile(file, "rw")) {
wavRaf.seek(0);
wavRaf.write(header);
} catch (Exception e) {
log.error("{},pcm转换成wav出错,{}", TAG, e.toString());
}
}
}
package ai.qiwu.com.tts_service.common.sound;
import javax.sound.sampled.*;
/**
* @dateTime 19-11-23 下午2:24
*/
public class AudioCommon {
private static boolean DEBUG = false;
public static void setDebug(boolean bDebug)
{
DEBUG = bDebug;
}
/** TODO:
*/
public static void listSupportedTargetTypes()
{
String strMessage = "Supported target types:";
AudioFileFormat.Type[] aTypes = AudioSystem.getAudioFileTypes();
for (int i = 0; i < aTypes.length; i++)
{
strMessage += " " + aTypes[i].getExtension();
}
out(strMessage);
}
/** Trying to get an audio file type for the passed extension.
This works by examining all available file types. For each
type, if the extension this type promisses to handle matches
the extension we are trying to find a type for, this type is
returned.
If no appropriate type is found, null is returned.
*/
public static AudioFileFormat.Type findTargetType(String strExtension)
{
AudioFileFormat.Type[] aTypes = AudioSystem.getAudioFileTypes();
for (int i = 0; i < aTypes.length; i++)
{
if (aTypes[i].getExtension().equals(strExtension))
{
return aTypes[i];
}
}
return null;
}
/** TODO:
*/
public static void listMixersAndExit()
{
out("Available Mixers:");
Mixer.Info[] aInfos = AudioSystem.getMixerInfo();
for (int i = 0; i < aInfos.length; i++)
{
out(aInfos[i].getName());
}
if (aInfos.length == 0)
{
out("[No mixers available]");
}
System.exit(0);
}
/** List Mixers.
Only Mixers that support either TargetDataLines or SourceDataLines
are listed, depending on the value of bPlayback.
*/
public static void listMixersAndExit(boolean bPlayback)
{
out("Available Mixers:");
Mixer.Info[] aInfos = AudioSystem.getMixerInfo();
for (int i = 0; i < aInfos.length; i++)
{
Mixer mixer = AudioSystem.getMixer(aInfos[i]);
Line.Info lineInfo = new Line.Info(bPlayback ?
SourceDataLine.class :
TargetDataLine.class);
if (mixer.isLineSupported(lineInfo))
{
out(aInfos[i].getName());
}
}
if (aInfos.length == 0)
{
out("[No mixers available]");
}
System.exit(0);
}
/** TODO:
This method tries to return a Mixer.Info whose name
matches the passed name. If no matching Mixer.Info is
found, null is returned.
*/
public static Mixer.Info getMixerInfo(String strMixerName)
{
Mixer.Info[] aInfos = AudioSystem.getMixerInfo();
for (int i = 0; i < aInfos.length; i++)
{
if (aInfos[i].getName().equals(strMixerName))
{
return aInfos[i];
}
}
return null;
}
/** TODO:
*/
public static TargetDataLine getTargetDataLine(String strMixerName,
AudioFormat audioFormat,
int nBufferSize)
{
/*
Asking for a line is a rather tricky thing.
We have to construct an Info object that specifies
the desired properties for the line.
First, we have to say which kind of line we want. The
possibilities are: SourceDataLine (for playback), Clip
(for repeated playback) and TargetDataLine (for
recording).
Here, we want to do normal capture, so we ask for
a TargetDataLine.
Then, we have to pass an AudioFormat object, so that
the Line knows which format the data passed to it
will have.
Furthermore, we can give Java Sound a hint about how
big the internal buffer for the line should be. This
isn't used here, signaling that we
don't care about the exact size. Java Sound will use
some default value for the buffer size.
*/
TargetDataLine targetDataLine = null;
DataLine.Info info = new DataLine.Info(TargetDataLine.class,
audioFormat, nBufferSize);
try
{
if (strMixerName != null)
{
Mixer.Info mixerInfo = getMixerInfo(strMixerName);
if (mixerInfo == null)
{
out("AudioCommon.getTargetDataLine(): mixer not found: " + strMixerName);
return null;
}
Mixer mixer = AudioSystem.getMixer(mixerInfo);
targetDataLine = (TargetDataLine) mixer.getLine(info);
}
else
{
if (DEBUG) { out("AudioCommon.getTargetDataLine(): using default mixer"); }
targetDataLine = (TargetDataLine) AudioSystem.getLine(info);
}
/*
* The line is there, but it is not yet ready to
* receive audio data. We have to open the line.
*/
if (DEBUG) { out("AudioCommon.getTargetDataLine(): opening line..."); }
targetDataLine.open(audioFormat, nBufferSize);
if (DEBUG) { out("AudioCommon.getTargetDataLine(): opened line"); }
}
catch (LineUnavailableException e)
{
if (DEBUG) { e.printStackTrace(); }
}
catch (Exception e)
{
if (DEBUG) { e.printStackTrace(); }
}
if (DEBUG) { out("AudioCommon.getTargetDataLine(): returning line: " + targetDataLine); }
return targetDataLine;
}
/** Checks if the encoding is PCM.
*/
public static boolean isPcm(AudioFormat.Encoding encoding)
{
return encoding.equals(AudioFormat.Encoding.PCM_SIGNED)
|| encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED);
}
/** TODO:
*/
private static void out(String strMessage)
{
System.out.println(strMessage);
}
}
package ai.qiwu.com.tts_service.common.sound;
import lombok.extern.slf4j.Slf4j;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* 合并wav文件
* @dateTime 19-11-25 下午3:05
*/
@Slf4j
public class AudioConcat {
private static final int MODE_NONE = 0;
private static final int MODE_MIXING = 1;
private static final int MODE_FLOATMIXING = 2;
private static final int MODE_CONCATENATION = 3;
/** Flag for debugging messages.
* If true, some messages are dumped to the console
* during operation.
*/
private static boolean DEBUG = false;
public static void audioContact(List<String> sourceList, String targetPath) {
AudioFormat audioFormat = null;
List audioInputStreamList = new ArrayList();
for (String path: sourceList)
{
File soundFile = new File(path);
AudioInputStream audioInputStream = null;
try
{
audioInputStream = AudioSystem.getAudioInputStream(soundFile);
}
catch (Exception e) {
log.error("合并时获取{}音频流出错",path);
return;
}
AudioFormat format = audioInputStream.getFormat();
if (audioFormat == null)
{
audioFormat = format;
if (DEBUG) { out("AudioConcat.main(): format: " + audioFormat); }
}
else if (!audioFormat.matches(format))
{
// TODO: try to convert
out("AudioConcat.main(): WARNING: AudioFormats don't match");
out("AudioConcat.main(): master format: " + audioFormat);
out("AudioConcat.main(): this format: " + format);
}
audioInputStreamList.add(audioInputStream);
}
AudioInputStream audioInputStream = new SequenceAudioInputStream(audioFormat, audioInputStreamList);
File outputFile = new File(targetPath);
try
{
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, outputFile);
}
catch (IOException e)
{
e.printStackTrace();
}
if (DEBUG) { out("AudioConcat.main(): before exit"); }
System.exit(0);
}
public static void main(String[] args)
{
/** Mode of operation.
Determines what to do with the input files:
either mixing or concatenation.
*/
int nMode = MODE_NONE;
String strOutputFilename = null;
AudioFormat audioFormat = null;
List audioInputStreamList = new ArrayList();
// int nExternalBufferSize = DEFAULT_EXTERNAL_BUFFER_SIZE;
// int nInternalBufferSize = AudioSystem.NOT_SPECIFIED;
/*
* Parsing of command-line options takes place...
*/
// Getopt g = new Getopt("AudioConcat", args, "hDcmfo:");
// int c;
// while ((c = g.getopt()) != -1)
// {
// switch (c)
// {
// case 'h':
// printUsageAndExit();
//
// case 'o':
// strOutputFilename = g.getOptarg();
// if (DEBUG) { out("AudioConcat.main(): output filename: " + strOutputFilename); }
// break;
//
// case 'c':
// nMode = MODE_CONCATENATION;
// break;
//
// case 'm':
// nMode = MODE_MIXING;
// break;
//
// case 'f':
// nMode = MODE_FLOATMIXING;
// break;
//
// case 'D':
// DEBUG = true;
// break;
//
// case '?':
// printUsageAndExit();
//
// default:
// out("AudioConcat.main(): getopt() returned " + c);
// break;
// }
// }
/*
* All remaining arguments are assumed to be filenames of
* soundfiles we want to play.
*/
// String strFilename = null;
// for (int i = g.getOptind(); i < args.length; i++)
// {
// strFilename = args[i];
// File soundFile = new File(strFilename);
//
// /*
// * We have to read in the sound file.
// */
// AudioInputStream audioInputStream = null;
// try
// {
// audioInputStream = AudioSystem.getAudioInputStream(soundFile);
// }
// catch (Exception e)
// {
// /*
// * In case of an exception, we dump the exception
// * including the stack trace to the console output.
// * Then, we exit the program.
// */
// e.printStackTrace();
// System.exit(1);
// }
// AudioFormat format = audioInputStream.getFormat();
// /*
// The first input file determines the audio format. This stream's
// AudioFormat is stored. All other streams are checked against
// this format.
// */
// if (audioFormat == null)
// {
// audioFormat = format;
// if (DEBUG) { out("AudioConcat.main(): format: " + audioFormat); }
// }
// else if ( ! audioFormat.matches(format))
// {
// // TODO: try to convert
// out("AudioConcat.main(): WARNING: AudioFormats don't match");
// out("AudioConcat.main(): master format: " + audioFormat);
// out("AudioConcat.main(): this format: " + format);
// }
// audioInputStreamList.add(audioInputStream);
// }
if (audioFormat == null)
{
out("No input filenames!");
printUsageAndExit();
}
AudioInputStream audioInputStream = null;
switch (nMode)
{
case MODE_CONCATENATION:
audioInputStream = new SequenceAudioInputStream(audioFormat, audioInputStreamList);
break;
case MODE_MIXING:
audioInputStream = new MixingAudioInputStream(audioFormat, audioInputStreamList);
break;
case MODE_FLOATMIXING:
// audioInputStream = new MixingFloatAudioInputStream(audioFormat, audioInputStreamList);
break;
default:
out("you have to specify a mode (either -m or -c).");
printUsageAndExit();
}
if (strOutputFilename == null)
{
out("you have to specify an output filename (using -o <filename>).");
printUsageAndExit();
}
File outputFile = new File(strOutputFilename);
try
{
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, outputFile);
}
catch (IOException e)
{
e.printStackTrace();
}
if (DEBUG) { out("AudioConcat.main(): before exit"); }
System.exit(0);
}
private static void printUsageAndExit()
{
out("AudioConcat: usage:");
out("\tjava AudioConcat -h");
out("\tjava AudioConcat [-D] -c|-m|-f -o <outputfile> <inputfile> ...");
System.exit(1);
}
private static void out(String strMessage)
{
System.out.println(strMessage);
}
}
package ai.qiwu.com.tts_service.common.sound;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import java.io.File;
import java.io.IOException;
/**
* @dateTime 19-11-23 下午3:47
*/
public class AudioDecoder {
private static final boolean DEBUG = false;
public static void main(String[] args)
{
// if (args.length != 2)
// {
// printUsageAndExit();
// }
// File encodedFile = new File(args[0]);
// File pcmFile = new File(args[1]);
File encodedFile = new File("/home/yf01/下载/tts/4.wav");
File pcmFile = new File("/home/yf01/下载/tts/4.pcm");
AudioInputStream ais = null;
try
{
ais = AudioSystem.getAudioInputStream(encodedFile);
}
catch (Exception e)
{
e.printStackTrace();
}
if (ais == null)
{
out("cannot open input file");
System.exit(1);
}
if (DEBUG) { out("AudioDecoder: ais: " + ais); }
if (DEBUG) { out("AudioDecoder: ais AudioFormat: " + ais.getFormat()); }
if (DEBUG) { out("AudioDecoder: ais length (frames): " + ais.getFrameLength()); }
AudioFormat.Encoding targetEncoding = AudioFormat.Encoding.PCM_SIGNED;
AudioInputStream pcmAIS = AudioSystem.getAudioInputStream(targetEncoding, ais);
if (DEBUG) { out("AudioDecoder: pcmAIS: " + pcmAIS); }
if (DEBUG) { out("AudioDecoder: pcmAIS AudioFormat: " + pcmAIS.getFormat()); }
if (DEBUG) { out("AudioDecoder: pcmAIS length (frames): " + pcmAIS.getFrameLength()); }
AudioFileFormat.Type fileType = AudioFileFormat.Type.AU;
int nWrittenBytes = 0;
try
{
nWrittenBytes = AudioSystem.write(pcmAIS, fileType, pcmFile);
if (DEBUG) out("AudioDecoder: written (bytes): " + nWrittenBytes);
}
catch (IOException e)
{
e.printStackTrace();
}
}
private static void printUsageAndExit()
{
out("AudioDecoder: usage:");
out("\tjava AudioDecoder <encodedfile> <pcmfile>");
System.exit(1);
}
private static void out(String strMessage)
{
System.out.println(strMessage);
}
}
package ai.qiwu.com.tts_service.common.sound;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
* @dateTime 19-11-25 下午3:06
*/
public class SequenceAudioInputStream extends AudioInputStream {
private static final boolean DEBUG = true;
private List m_audioInputStreamList;
private int m_nCurrentStream;
public SequenceAudioInputStream(AudioFormat audioFormat, Collection audioInputStreams)
{
super(new ByteArrayInputStream(new byte[0]), audioFormat, AudioSystem.NOT_SPECIFIED);
m_audioInputStreamList = new ArrayList(audioInputStreams);
m_nCurrentStream = 0;
}
// TODO: remove
private boolean addAudioInputStream(AudioInputStream audioStream)
{
if (DEBUG)
{
out("SequenceAudioInputStream.addAudioInputStream(): called.");
}
// Contract.check(audioStream != null);
if (!getFormat().matches(audioStream.getFormat()))
{
if (DEBUG)
{
out("SequenceAudioInputStream.addAudioInputStream(): audio formats do not match, trying to convert.");
}
AudioInputStream asold = audioStream;
audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);
if (audioStream == null)
{
out("### SequenceAudioInputStream.addAudioInputStream(): could not convert.");
return false;
}
if (DEBUG)
{
out(" converted");
}
}
// Contract.check(audioStream != null);
synchronized (m_audioInputStreamList)
{
m_audioInputStreamList.add(audioStream);
m_audioInputStreamList.notifyAll();
}
if (DEBUG)
{
out("SequenceAudioInputStream.addAudioInputStream(): enqueued " + audioStream);
}
return true;
}
private AudioInputStream getCurrentStream()
{
return (AudioInputStream) m_audioInputStreamList.get(m_nCurrentStream);
}
private boolean advanceStream()
{
m_nCurrentStream++;
boolean bAnotherStreamAvailable = (m_nCurrentStream < m_audioInputStreamList.size());
return bAnotherStreamAvailable;
}
public long getFrameLength()
{
long lLengthInFrames = 0;
Iterator streamIterator = m_audioInputStreamList.iterator();
while (streamIterator.hasNext())
{
AudioInputStream stream = (AudioInputStream) streamIterator.next();
long lLength = stream.getFrameLength();
if (lLength == AudioSystem.NOT_SPECIFIED)
{
return AudioSystem.NOT_SPECIFIED;
}
else
{
lLengthInFrames += lLength;
}
}
return lLengthInFrames;
}
public int read()
throws IOException
{
AudioInputStream stream = getCurrentStream();
int nByte = stream.read();
if (nByte == -1)
{
/*
The end of the current stream has been signaled.
We try to advance to the next stream.
*/
boolean bAnotherStreamAvailable = advanceStream();
if (bAnotherStreamAvailable)
{
/*
There is another stream. We recurse into this method
to read from it.
*/
return read();
}
else
{
/*
No more data. We signal EOF.
*/
return -1;
}
}
else
{
/*
The most common case: We return the byte.
*/
return nByte;
}
}
public int read(byte[] abData, int nOffset, int nLength)
throws IOException
{
AudioInputStream stream = getCurrentStream();
int nBytesRead = stream.read(abData, nOffset, nLength);
if (nBytesRead == -1)
{
/*
The end of the current stream has been signaled.
We try to advance to the next stream.
*/
boolean bAnotherStreamAvailable = advanceStream();
if (bAnotherStreamAvailable)
{
/*
There is another stream. We recurse into this method
to read from it.
*/
return read(abData, nOffset, nLength);
}
else
{
/*
No more data. We signal EOF.
*/
return -1;
}
}
else
{
/*
The most common case: We return the length.
*/
return nBytesRead;
}
}
public long skip(long lLength)
throws IOException
{
throw new IOException("skip() is not implemented in class SequenceInputStream. Mail if you need this feature.");
}
public int available()
throws IOException
{
return getCurrentStream().available();
}
public void close()
throws IOException
{
// TODO: should we close all streams in the list?
}
public void mark(int nReadLimit)
{
throw new RuntimeException("mark() is not implemented in class SequenceInputStream. Mail if you need this feature.");
}
public void reset()
throws IOException
{
throw new IOException("reset() is not implemented in class SequenceInputStream. Mail if you need this feature.");
}
public boolean markSupported()
{
return false;
}
private static void out(String strMessage)
{
System.out.println(strMessage);
}
}
......@@ -2,41 +2,18 @@ package ai.qiwu.com.tts_service.service;
import ai.qiwu.com.tts_service.common.OkHttp3Utils;
import ai.qiwu.com.tts_service.common.TTSUtils;
import ai.qiwu.com.tts_service.common.TTServiceUtil;
import ai.qiwu.com.tts_service.common.sound.SampleRateConverter;
import ai.qiwu.com.tts_service.pojo.TtsLsAudio;
import ai.qiwu.com.tts_service.pojo.TtsLsResponse;
import ai.qiwu.com.tts_service.pojo.TtsLsType;
import ai.qiwu.com.tts_service.pojo.upload.UploadOneSenData;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.csvreader.CsvReader;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.util.CollectionUtils;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.*;
import java.math.BigInteger;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static ai.qiwu.com.tts_service.pojo.TtsLsType.*;
/**
* @author 苗权威
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment