<commit_before>package cn.yiiguxing.plugin.translate.tts

import cn.yiiguxing.plugin.translate.trans.Lang
import cn.yiiguxing.plugin.translate.util.checkDispatchThread
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project

/**
 * Text to speech.
 */
class TextToSpeech private constructor() {

    private var currentPlayer: TTSPlayer? = null

    /**
     * Text to speech.
     *
     * @param project the project.
     * @param text the text.
     * @param lang the language.
     */
    fun speak(project: Project?, text: String, lang: Lang): Disposable {
        checkThread()
        currentPlayer?.stop()

        return GoogleTTSPlayer(project, text, lang) { player ->
            if (player === currentPlayer) {
                currentPlayer = null
            }
        }.run {
            currentPlayer = this
            start()

            disposable
        }
    }

    /**
     * Returns `true` if the [language][lang] is supported.
     */
    fun isSupportLanguage(lang: Lang): Boolean = GoogleTTSPlayer.SUPPORTED_LANGUAGES.contains(lang)<commit_msg>Refactoring<commit_after>package cn.yiiguxing.plugin.translate.tts

import cn.yiiguxing.plugin.translate.trans.Lang
import cn.yiiguxing.plugin.translate.util.checkDispatchThread
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project

/**
 * Text to speech.
 */
class TextToSpeech private constructor() {

    private var currentPlayer: TTSPlayer? = null

    /**
     * Text to speech.
     *
     * @param project the project.
     * @param text the text.
     * @param lang the language.
     */
    fun speak(project: Project?, text: String, lang: Lang): Disposable {
        checkThread()
        currentPlayer?.stop()

        return GoogleTTSPlayer(project, text, lang) { player ->
            if (player === currentPlayer) {
                currentPlayer = null
            }
        }.let {
            currentPlayer = it
            it.start()

            it.disposable
        }
    }

    /**
     * Returns `true` if the [language][lang] is supported.
     */
    fun isSupportLanguage(lang: Lang): Boolean = GoogleTTSPlayer.SUPPORTED_LANGUAGES.contains(lang)
{'fraction_non_alphanumeric': 0.10407632263660017, 'fraction_numerical': 0.0, 'mean_word_length': 2.4484304932735426, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2404251', 'n_tokens_mistral': 682, 'n_tokens_neox': 653, 'n_words': 151}