Skip to content

Commit

Permalink
読み上げ文字数の制限に達した際の処理を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
kosugikun committed Mar 29, 2023
1 parent b2c175d commit d1dc852
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/main/java/dev/cosgy/textToSpeak/audio/Dictionary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.function.BiFunction

class Dictionary private constructor(private val bot: Bot) {
class Dictionary private constructor(bot: Bot) {
private val logger = LoggerFactory.getLogger(this.javaClass)
private val path: Path?
private val create: Boolean
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/dev/cosgy/textToSpeak/audio/VoiceCreation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory
import java.io.*
import java.nio.file.Files
import java.nio.file.Paths
import java.text.BreakIterator
import java.util.*

class VoiceCreation( // 各種設定の値を保持するためのフィールド
Expand Down Expand Up @@ -68,9 +69,27 @@ class VoiceCreation( // 各種設定の値を保持するためのフィール
private fun sanitizeMessage(message: String): String {
var sanitizedMsg = message.replace("[\\uD800-\\uDFFF]".toRegex(), " ")
sanitizedMsg = sanitizedMsg.replace("Kosugi_kun".toRegex(), "コスギクン")
return sanitizedMsg
val sentences = BreakIterator.getSentenceInstance(Locale.JAPANESE)
sentences.setText(sanitizedMsg)
var messageCount = 0
var lastIndex = 0
val builder = StringBuilder()
while (sentences.next() != BreakIterator.DONE) {
val sentence = sanitizedMsg.substring(lastIndex, sentences.current())
if (sentence.length + builder.length > maxMessageCount) {
builder.append("以下略")
break
}
builder.append(sentence)
builder.append("\n")
messageCount++
lastIndex = sentences.current()
}
return builder.toString()
}



// テキストファイルを作成するメソッド
@Throws(FileNotFoundException::class, UnsupportedEncodingException::class)
private fun createTmpTextFile(guildId: String, fileId: String, message: String): String {
Expand Down

0 comments on commit d1dc852

Please sign in to comment.