Skip to content

Commit

Permalink
Merge pull request #13 from umjammer/0.0.12
Browse files Browse the repository at this point in the history
0.0.12
  • Loading branch information
umjammer committed Mar 4, 2024
2 parents b3c6eb3 + 023b33e commit e88906e
Show file tree
Hide file tree
Showing 20 changed files with 174 additions and 158 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Release](https://jitpack.io/v/umjammer/vavi-speech2.svg)](https://jitpack.io/#umjammer/vavi-speech2)
[![Java CI](https://github.com/umjammer/vavi-speech2/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/vavi-speech2/actions)
[![Java CI](https://github.com/umjammer/vavi-speech2/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/vavi-speech2/actions/workflows/maven.yml)
[![CodeQL](https://github.com/umjammer/vavi-speech2/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/umjammer/vavi-speech2/actions/workflows/codeql-analysis.yml)
![Java](https://img.shields.io/badge/Java-17-b07219)

Expand Down Expand Up @@ -81,4 +81,4 @@ Text to Speech and Speech to Text (JSAPI2) engines for Java
* [SHAREVOX](https://www.sharevox.app)
* [http://itvoice.starfree.jp/](http://itvoice.starfree.jp/)
* AVSpeechSynthesizer needs block
* rcp client/server (wip)
* ~~rcp client/server (wip)~~ -> [vavi-speech-rpc](https://github.com/umjammer/vavi-speech-rpc)
27 changes: 9 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>vavi</groupId>
<artifactId>vavi-speech2</artifactId>
<version>0.0.11</version>
<version>0.0.12</version>

<name>vavi-speech2</name>
<description/>
Expand All @@ -22,16 +22,10 @@

<properties>
<jsapi2.groupId>com.github.umjammer.jsapi</jsapi2.groupId> <!-- org.jvoicexml / com.github.umjammer.jsapi -->
<jsapi2.version>0.6.5</jsapi2.version>
<jersey.version>3.1.1</jersey.version>
</properties>
<jsapi2.version>0.6.6</jsapi2.version>

<distributionManagement>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/umjammer/vavi-speech2</url>
</repository>
</distributionManagement>
<jersey.version>3.1.5</jersey.version>
</properties>

<profiles>
<profile>
Expand Down Expand Up @@ -86,6 +80,7 @@
</environmentVariables>
<argLine>
-Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties
-Dvavi.util.logging.VaviFormatter.extraClassMethod=sun\\.util\\.logging\\.internal\\.LoggingProviderImpl.*r#log
</argLine>
<includes>
<include>**/*Test_*.java</include>
Expand Down Expand Up @@ -176,10 +171,6 @@
</build>

<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/umjammer/*</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
Expand All @@ -199,7 +190,7 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.1</version>
<version>5.10.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -228,7 +219,7 @@
<dependency>
<groupId>com.github.umjammer</groupId> <!-- vavi / com.github.umjammer -->
<artifactId>vavi-speech</artifactId>
<version>0.1.8</version>
<version>0.1.9</version>
<exclusions>
<exclusion>
<groupId>javax.speech</groupId>
Expand Down Expand Up @@ -274,7 +265,7 @@
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.2</version>
<version>2.1.3</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -302,7 +293,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>2.0.5</version>
<version>2.0.11</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class AquesTalk10EngineListFactory implements EngineListFactory {

@Override
public EngineList createEngineList(EngineMode require) {
if (require instanceof SynthesizerMode) {
SynthesizerMode mode = (SynthesizerMode) require;
if (require instanceof SynthesizerMode mode) {
List<Voice> allVoices = getVoices();
List<Voice> voices = new ArrayList<>();
if (mode.getVoices() == null) {
Expand All @@ -54,7 +53,7 @@ public EngineList createEngineList(EngineMode require) {
mode.getRunning(),
mode.getSupportsLetterToSound(),
mode.getMarkupSupport(),
voices.toArray(new Voice[0]))
voices.toArray(Voice[]::new))
};
return new EngineList(features);
}
Expand All @@ -67,7 +66,7 @@ public EngineList createEngineList(EngineMode require) {
*
* @return all voices
*/
private List<Voice> getVoices() {
private static List<Voice> getVoices() {
List<Voice> voiceList = new LinkedList<>();
for (Map.Entry<String, AQTK_VOICE> aquesTalkVoice : AquesTalk10Wrapper.voices.entrySet()) {
Voice voice = new Voice(new SpeechLocale(Locale.JAPAN.toString()),
Expand All @@ -82,11 +81,10 @@ private List<Voice> getVoices() {

/** */
private static int toGender(AQTK_VOICE voice) {
switch (voice.bas) {
case 0: return Voice.GENDER_FEMALE;
case 1: return Voice.GENDER_FEMALE;
case 2: return Voice.GENDER_MALE;
default: return Voice.GENDER_DONT_CARE;
}
return switch (voice.bas) {
case 0, 1 -> Voice.GENDER_FEMALE;
case 2 -> Voice.GENDER_MALE;
default -> Voice.GENDER_DONT_CARE;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
public final class AquesTalk10Synthesizer extends BaseSynthesizer {

/** Logger for this class. */
private static final Logger LOGGER = Logger.getLogger(AquesTalk10Synthesizer.class.getName());
private static final Logger logger = Logger.getLogger(AquesTalk10Synthesizer.class.getName());

/** */
@Property(binder = InstanciationBinder.class, value = "vavi.speech.phoneme.KuromojiJaPhonemer")
Expand Down Expand Up @@ -72,16 +72,16 @@ protected void handleAllocate() throws EngineStateException, EngineException, Au
Voice voice;
AquesTalk10SynthesizerMode mode = (AquesTalk10SynthesizerMode) getEngineMode();
if (mode == null) {
voice = null;
throw new EngineException("not engine mode");
} else {
Voice[] voices = mode.getVoices();
if (voices == null) {
voice = null;
if (voices == null || voices.length < 1) {
throw new EngineException("no voice");
} else {
voice = voices[0];
}
}
LOGGER.fine("default voice: " + voice.getName());
logger.fine("default voice: " + voice.getName());
getSynthesizerProperties().setVoice(voice);

aquesTalk10 = AquesTalk10Wrapper.getInstance();
Expand All @@ -95,7 +95,7 @@ protected void handleAllocate() throws EngineStateException, EngineException, Au
/**
* @param voice when null, returns default voice.
*/
private AQTK_VOICE toNativeVoice(Voice voice) {
private static AQTK_VOICE toNativeVoice(Voice voice) {
return AquesTalk10Wrapper.voices.get(voice == null ? "F1" : voice.getName());
}

Expand All @@ -119,7 +119,7 @@ public void handleDeallocate() {
// Leave some time to let all resources detach
try {
Thread.sleep(500);
} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
}
aquesTalk10 = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public class GoogleCloudEngineListFactory implements EngineListFactory {

@Override
public EngineList createEngineList(EngineMode require) {
if (require instanceof SynthesizerMode) {
SynthesizerMode mode = (SynthesizerMode) require;
if (require instanceof SynthesizerMode mode) {
List<Voice> allVoices = getVoices();
List<Voice> voices = new ArrayList<>();
if (mode.getVoices() == null) {
Expand All @@ -56,7 +55,7 @@ public EngineList createEngineList(EngineMode require) {
mode.getRunning(),
mode.getSupportsLetterToSound(),
mode.getMarkupSupport(),
voices.toArray(new Voice[0]))
voices.toArray(Voice[]::new))
};
return new EngineList(features);
}
Expand All @@ -69,7 +68,7 @@ public EngineList createEngineList(EngineMode require) {
*
* @return all voices
*/
private List<Voice> getVoices() {
private static List<Voice> getVoices() {
List<Voice> voiceList = new LinkedList<>();
for (com.google.cloud.texttospeech.v1.Voice nativeVoice : listAllSupportedVoices()) {
Voice voice = new Voice(new SpeechLocale(nativeVoice.getLanguageCodes(0)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jvoicexml.jsapi2.recognition.BaseRecognizer;
import org.jvoicexml.jsapi2.recognition.BaseResult;
import org.jvoicexml.jsapi2.recognition.GrammarDefinition;
import vavi.util.Debug;


/**
Expand Down Expand Up @@ -90,19 +91,18 @@ protected boolean handleResume(InputStream in) throws EngineStateException {
file.deleteOnExit();
FileOutputStream out = new FileOutputStream(file);

StringBuffer xml = new StringBuffer();
StringBuilder xml = new StringBuilder();
xml.append(grammar.toString());
int index = xml.indexOf("06/grammar");
xml.insert(index + 11, " xml:lang=\"de-DE\" ");
out.write(xml.toString().getBytes());
out.close();
grammarSources[i] = file.getCanonicalPath();
// System.out.println(xml);
// System.out.println(grammarSources[i]);
//Debug.println(xml);
//Debug.println(grammarSources[i]);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Debug.printStackTrace(e);
}
++i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
* @version 0.00 2019/09/20 umjammer initial version <br>
*/
public final class GoogleCloudTextToSpeechSynthesizer extends BaseSynthesizer {

/** Logger for this class. */
private static final Logger LOGGER = Logger.getLogger(GoogleCloudTextToSpeechSynthesizer.class.getName());
private static final Logger logger = Logger.getLogger(GoogleCloudTextToSpeechSynthesizer.class.getName());

/** */
private TextToSpeechClient client;
Expand All @@ -63,16 +64,16 @@ protected void handleAllocate() throws EngineStateException, EngineException, Au
Voice voice;
GoogleCloudTextToSpeechSynthesizerMode mode = (GoogleCloudTextToSpeechSynthesizerMode) getEngineMode();
if (mode == null) {
voice = null;
throw new EngineException("not engine mode");
} else {
Voice[] voices = mode.getVoices();
if (voices == null) {
voice = null;
if (voices == null || voices.length < 1) {
throw new EngineException("no voice");
} else {
voice = voices[0];
}
}
LOGGER.fine("default voice: " + voice.getName());
logger.fine("default voice: " + voice.getName());
getSynthesizerProperties().setVoice(voice);

try {
Expand All @@ -88,7 +89,7 @@ protected void handleAllocate() throws EngineStateException, EngineException, Au
}

/** */
private com.google.cloud.texttospeech.v1.Voice toNativeVoice(Voice voice) {
private static com.google.cloud.texttospeech.v1.Voice toNativeVoice(Voice voice) {
if (voice == null) {
return null;
}
Expand Down Expand Up @@ -116,7 +117,7 @@ public void handleDeallocate() {
// Leave some time to let all resources detach
try {
Thread.sleep(500);
} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
}
client.close();

Expand All @@ -138,7 +139,7 @@ public boolean handleResume() {
@Override
public AudioSegment handleSpeak(int id, String item) {
try {
byte[] bytes = synthe(item);
byte[] bytes = synthesis(item);
AudioManager manager = getAudioManager();
String locator = manager.getMediaLocator();
// you should pass bytes to BaseAudioSegment as AudioInputStream or causes crackling!
Expand All @@ -156,7 +157,7 @@ public AudioSegment handleSpeak(int id, String item) {
}

/** */
private byte[] synthe(String text) {
private byte[] synthesis(String text) {
SynthesisInput input = SynthesisInput.newBuilder().setText(text).build();

VoiceSelectionParams voice = VoiceSelectionParams.newBuilder()
Expand Down
Loading

0 comments on commit e88906e

Please sign in to comment.