Skip to content

Commit

Permalink
Merge pull request #12 from umjammer/0.1.9
Browse files Browse the repository at this point in the history
0.1.9
  • Loading branch information
umjammer authored Mar 4, 2024
2 parents 865da8d + f90bdef commit f77c64d
Show file tree
Hide file tree
Showing 27 changed files with 111 additions and 91 deletions.
7 changes: 5 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-speech.svg)](https://jitpack.io/#umjammer/vavi-speech)
[![Java CI](https://github.com/umjammer/vavi-speech/workflows/Java%20CI%20with%20Maven/badge.svg)](https://github.com/umjammer/vavi-speech/actions)
[![Java CI](https://github.com/umjammer/vavi-speech/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/vavi-speech/actions/workflows/maven.yml)
[![CodeQL](https://github.com/umjammer/vavi-speech/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/umjammer/vavi-speech/actions/workflows/codeql-analysis.yml)
![Java](https://img.shields.io/badge/Java-17-b07219)
[![Parent](https://img.shields.io/badge/Parent-vavi--speech2-pink)](https://github.com/umjammer/vavi-speech2)
Expand All @@ -18,7 +18,7 @@ Text to Speech (JSAPI) engines for Java and Japanese phonemeizers
| Rococoa | [Rococoa](https://github.com/iterate-ch/rococoa/blob/d5fdd3b884d5f044bc0b168aff66e5f52a014da8/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/appkit/NSSpeechSynthesizerTest.java), JNA ||| 😃 | |
| FreeTTS | [FreeTTS](https://github.com/umjammer/FreeTTS/) | - || 💩 | not included (test only) |

## Kanji -> Kana converter
## Kanji to Kana converter

| **Type** | **Description** | **Staus** | **Quality** | **Comment** |
|:---------|:----------------|:---------:|:-----------:|:------------|
Expand Down Expand Up @@ -146,6 +146,9 @@ phonemer=vavi.speech.phoneme.KuromojiJaPhonemer
* ずんだもん ([wip](src/main/resources/vavi/speech/modifier/yakuwarigo/zundamon/rule.json))
* unify japanese tokenizer (lucene-gosen?)
* AVSpeechSynthesizer needs obj-c block
* access private
* reflection -> JEP 193: Variable Handles https://qiita.com/yoshioterada/items/319ed0dec4b847d2b1ed
* https://github.com/FabricMC/access-widener

### Morphological Analyzer

Expand Down
13 changes: 10 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>vavi</groupId>
<artifactId>vavi-speech</artifactId>
<version>0.1.8</version>
<version>0.1.9</version>

<name>vavi-speech</name>
<description/>
Expand Down Expand Up @@ -234,7 +234,7 @@
<url>https://gitlab.com/api/v4/projects/30804899/packages/maven</url>
</repository>
<repository>
<id>gitlab-maven-sen</id>
<id>gitlab-maven2-sen</id>
<url>https://gitlab.com/api/v4/projects/18523814/packages/maven</url>
</repository>
</repositories>
Expand All @@ -252,7 +252,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 @@ -407,5 +407,12 @@
<version>${freetts.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.9.6</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public class AquesTalkSynthesizer implements Synthesizer {
private AquesTalkDa aquesTalkDa;

/** */
private SynthesizerModeDesc desc;
private final SynthesizerModeDesc desc;

/** */
private SynthesizerProperties properties = new BaseSynthesizerProperties();
private final SynthesizerProperties properties = new BaseSynthesizerProperties();

/**
* Creates a new Synthesizer in the DEALLOCATED state.
Expand All @@ -62,8 +62,8 @@ public AquesTalkSynthesizer(AquesTalkSynthesizerModeDesc desc) {
this.desc = desc;
}

/** */
private Phonemizer phonemizer = new SenJaPhonemizer();
/** TODO outsource? */
private final Phonemizer phonemizer = new SenJaPhonemizer();

/**
* <pre>
Expand Down Expand Up @@ -194,7 +194,7 @@ public void removeEngineListener(EngineListener listener) {

@Override
public void resume() throws AudioException, EngineStateError {
while (queue.size() > 0) {
while (!queue.isEmpty()) {
Pair pair = queue.poll();
if (pair.listener != null) {
pair.listener.speakableStarted(new SpeakableEvent(this, 0));
Expand Down Expand Up @@ -222,5 +222,3 @@ public boolean testEngineState(long state) throws IllegalArgumentException {
public void waitEngineState(long state) throws InterruptedException, IllegalArgumentException {
}
}

/* */
2 changes: 1 addition & 1 deletion src/main/java/vavi/speech/aquestalk10/jna/AquesTalk10.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ enum VoiceBase {
int AquesTalk_SetUsrKey(byte[] key);

/** メソッドが返すエラーコードの内容 */
Map<Integer, String> errors = new HashMap<Integer, String>() {{
Map<Integer, String> errors = new HashMap<>() {{
put(100, "その他のエラー");
put(101, "メモリ不足");
put(103, "音声記号列指定エラー(語頭の長音、促音の連続など)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static AquesTalk10Wrapper getInstance() {
private AquesTalk10Wrapper() {}

/** */
public static final Map<String, AQTK_VOICE> voices = new HashMap<String, AQTK_VOICE>() {
public static final Map<String, AQTK_VOICE> voices = new HashMap<>() {
{
put("F1", AquesTalk10.gVoice_F1);
put("F2", AquesTalk10.gVoice_F2);
Expand All @@ -86,7 +86,7 @@ public void setVoice(AQTK_VOICE voice) {

/** text replacement table before speaking */
private static final FormattedPropertiesFactory.Basic replaceMap =
new FormattedPropertiesFactory.Basic("/aquestalk.properties", "text.replace.%s");
new FormattedPropertiesFactory.Basic("/aquestalk10.properties", "text.replace.%s");

/**
* @return PCM wave format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void speak(Pair pair) throws EngineStateError {
}

/** */
private List<EngineListener> listeners = new ArrayList<>();
private final List<EngineListener> listeners = new ArrayList<>();

@Override
public void addEngineListener(EngineListener listener) {
Expand All @@ -195,8 +195,8 @@ public void addEngineListener(EngineListener listener) {
/** */
private boolean playing;

/** */
private Player player = new vavi.speech.JavaSoundPlayer();
/** TODO outsource? */
private final Player player = new vavi.speech.JavaSoundPlayer();

@Override
public void allocate() throws EngineException, EngineStateError {
Expand All @@ -222,7 +222,7 @@ public void allocate() throws EngineException, EngineStateError {
}
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
Debug.printStackTrace(e);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public 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 -> Voice.GENDER_FEMALE;
case 1 -> Voice.GENDER_FEMALE;
case 2 -> Voice.GENDER_MALE;
default -> Voice.GENDER_DONT_CARE;
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void speak(Pair pair) throws EngineStateError {
}

/** */
private List<EngineListener> listeners = new ArrayList<>();
private final List<EngineListener> listeners = new ArrayList<>();

@Override
public void addEngineListener(EngineListener listener) {
Expand All @@ -178,7 +178,7 @@ public void addEngineListener(EngineListener listener) {
private boolean playing;

/** */
private Player player = new JavaSoundPlayer();
private final Player player = new JavaSoundPlayer();

@Override
public void allocate() throws EngineException, EngineStateError {
Expand All @@ -196,15 +196,15 @@ public void allocate() throws EngineException, EngineStateError {
playing = true;
Debug.println(Level.FINE, "\n" + pair.text);
player.setVolume(properties.getVolume());
player.play(synthe(pair.text));
player.play(synthesis(pair.text));
playing = false;
if (pair.listener != null) {
pair.listener.speakableEnded(new SpeakableEvent(GoogleCloudTextToSpeechSynthesizer.this, SpeakableEvent.SPEAKABLE_ENDED));
}
}
Thread.sleep(300);
} catch (Exception e) {
e.printStackTrace();
Debug.printStackTrace(e);
}
}
});
Expand All @@ -214,7 +214,7 @@ public void allocate() throws EngineException, EngineStateError {
}

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

VoiceSelectionParams voice = VoiceSelectionParams.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String convert2keitai(String input) {
return convert(input);
}

private boolean isX(String x) {
private static boolean isX(String x) {
return x.equals("ました") || x.equals("ります");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static EQMark sampleExclamationQuestionByValue(String v) {
}
}
// 到達しないはずだけれど一応いれてる;
if (s.size() < 1) {
if (s.isEmpty()) {
return null;
}

Expand All @@ -126,7 +126,7 @@ static EQMark findExclamationQuestionByStyleAndMeaning(StyleType s, MeaningType
eq.add(mark);
}
}
if (eq.size() < 1) {
if (eq.isEmpty()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,14 @@ public StringResult newLongNote(int p) {
int e = randomizer.exclamationMarkCount();

StringBuilder suffix = new StringBuilder();
for (int i = 0; i < w; i++) {
suffix.append("~");
}
suffix.append("~".repeat(Math.max(0, w)));

// !or?をどれかからランダムに選択する
EQMark feq = sampleExclamationQuestionByValue(s);

// 次の token は必ず感嘆符か疑問符のどちらかであることが確定しているため
// -1 して数を調整している。
for (int i = 0; i < e - 1; i++) {
suffix.append(feq.value);
}
suffix.append(String.valueOf(feq.value).repeat(Math.max(0, e - 1)));

// 後ろに!や?が連続する場合、それらをすべて feq と同じ種類(半角、全角、
// 絵文字)の!や?に置き換えて返却する。
Expand Down Expand Up @@ -262,7 +258,7 @@ public StringResult randomKutenToExclamation(int tokenPos) {
//----

/** */
private boolean isPrefixAppendable(TokenData data) {
private static boolean isPrefixAppendable(TokenData data) {
if (!equalsFeatures(data.features, new Feature.Feat().setElements("名詞", "一般")) &&
!equalsFeatures(slice(data.features, 0, 2), new Feature.Feat().setElements("名詞", "固有名詞"))) {
return false;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/vavi/speech/phonemizer/DigitJaPhonemizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private static String decideNumberKana(NumberPhoneType type, NumberPhoneType pre
*/
public String convertFrom(String src) {
Matcher matcher = rexNumber.matcher(src);
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
while (matcher.find()) {
matcher.appendReplacement(sb, phoneme(matcher.group(1)));
}
Expand All @@ -409,7 +409,7 @@ public String phoneme(String src) {
String[] numParts = getNumberParts(src);

// 小数部の有無
boolean remainExist = numParts.length >= 2 && numParts[1].length() > 0;
boolean remainExist = numParts.length >= 2 && !numParts[1].isEmpty();

// 整数部の読み仮名をバッファに追加
appendNumberPhonetic(numParts[0], remainExist, dest);
Expand All @@ -428,7 +428,7 @@ public String phoneme(String src) {
* @param src 数字を表す文字列。
* @return 整数部文字列と小数部文字列の配列。
*/
private String[] getNumberParts(String src) {
private static String[] getNumberParts(String src) {
// 全角を半角に変換
String text = CharNormalizerJa.ToHalf.normalize(src);

Expand Down Expand Up @@ -551,7 +551,7 @@ private int appendThousandPartPhonetic(String src,
if (len == 0) {
// "0" のみだった場合
String zero = decideNumberKana(NumberPhoneType.Digit0, lastType, baseType);
if (zero.length() > 0) {
if (!zero.isEmpty()) {
dest.append(zero);
lastType = NumberPhoneType.Digit0;
}
Expand Down Expand Up @@ -579,7 +579,7 @@ private int appendThousandPartPhonetic(String src,
NumberPhoneType t = types.get(i);
NumberPhoneType next = i + 1 < types.size() ? types.get(i + 1) : baseType;
String s = decideNumberKana(t, lastType, next);
if (s.length() > 0) {
if (!s.isEmpty()) {
dest.append(s);
lastType = t;
}
Expand All @@ -591,7 +591,7 @@ private int appendThousandPartPhonetic(String src,
// - 1文字以上追加があった
if (baseType.isPoint() || dest.length() > oldLen) {
String baseText = decideNumberKana(baseType, lastType, NumberPhoneType.None);
if (baseText.length() > 0) {
if (!baseText.isEmpty()) {
dest.append(baseText);
lastType = baseType;
}
Expand All @@ -606,7 +606,7 @@ private int appendThousandPartPhonetic(String src,
* @param c 文字。
* @return 数値。変換できなければ 0 。
*/
private int parseChar(char c) {
private static int parseChar(char c) {
return Character.isDigit(c) ? Integer.parseInt(String.valueOf(c)) : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SudachiJaPhonemizer implements JaPhonemizer {
public SudachiJaPhonemizer() {
try {
Config config = Config.fromClasspath("sudachi.json");
Dictionary dict = new DictionaryFactory().create(config);
Dictionary dict = new DictionaryFactory().create(config); // DON'T CLOSE in this block
tokenizer = dict.create();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try { dict.close(); } catch (IOException e) { throw new UncheckedIOException(e); }
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/vavi/speech/phonemizer/YahooJapanJaPhonemizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ public String toString() {
roman;
return sb;
}
static final String BODY = "" +
"{\n" +
" \"id\": \"{0}\",\n" +
" \"jsonrpc\": \"2.0\",\n" +
" \"method\": \"jlp.furiganaservice.furigana\",\n" +
" \"params\": {\n" +
" \"q\": \"{1}\",\n" +
" \"grade\": 1\n" +
" }\n" +
"}";
static final String BODY = """
{
"id": "{0}",
"jsonrpc": "2.0",
"method": "jlp.furiganaservice.furigana",
"params": {
"q": "{1}",
"grade": 1
}
}""";
static final String UA = "Yahoo AppID: %s";
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vavi/speech/rococoa/SynthesizerDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void waitForWord(long interval, String word) {
}

@SuppressWarnings("unused")
private String getCallerName() {
private static String getCallerName() {
for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
if (ste.getMethodName().startsWith("test")) {
return ste.getMethodName();
Expand Down
Loading

0 comments on commit f77c64d

Please sign in to comment.