a tool to better use TextToSpeach and SoundPool
You can download a jar from GitHub's releases page.
Or use Gradle:
repositories {
mavenCentral()
google()
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.fytuuu:PigMediaStudio:v1.0'
}
init PigSoundPlayer before you play sound. you may call initSoundPlayer()
in application.
PigSoundPlayer.initSoundPlayer(1);
Before you play sound (resource or local file), load it in to the pool. The result is id of this file.
int result = PigSoundPlayer.getLoader(getApplicationContext()).load(filePath,1);
then you may call play() to play target sound stream.
int streamID = PigSoundPlayer.play(fileName,1.0f,1.0f,1,0,1.0f)
also you may pause one of them by calling
PigSoundPlayer.pause(streamID)
or pause all of them by calling
PigSoundPlayer.autoPause()
stop one of them by calling
PigSoundPlayer.stop(streamID)
you may load it to the PigReader
,it will read the text after read all texts before it in the queue.
PigSpeechManager.in(getApplicationContext()).getReader().setSpeed(3.0f).setPitch(0.5f).loadReadTTS(text);
or read a text now. In this case, the text that is read will be flushed and abandoned.After read the readNow(text)
, subsequent text int the queue will be read.
PigSpeechManager.in(getApplicationContext()).getReader().readNow(str);
before transforming, you'd better check the write permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
PigSpeechManager.in(getApplicationContext()).getTranslater().setWavSpeed(1.0f).put(fileName,text);
you may set a translateProgressListener
to see witch file has been created
PigSpeechManager.in(context).getTranslater().setParentPath("test").setOnTranslatProgressListener(new PigTranslater.OnTranslateProgressListener(){
@Override
public void onStart(){}
@Override
public void onComplete(String text,String fileAbsolutePath){
}
@Override
public void onError(String error){
}
}
Blog site:
开发PigMediaStudio依赖库过程记录(一)
https://blog.csdn.net/weixin_43093006/article/details/98993551
开发PigMediaStudio依赖库过程记录(二)
https://blog.csdn.net/weixin_43093006/article/details/99355667