This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a935fc9
commit 82c55d9
Showing
8 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package tts | ||
|
||
import com.jacob.activeX.ActiveXComponent | ||
import com.jacob.com.Dispatch | ||
import com.jacob.com.Variant | ||
import state.getResourcesFile | ||
|
||
class MSTTSpeech { | ||
|
||
/** 音量 1到100 */ | ||
var volume: Int = 100 | ||
|
||
/** 频率 -10到10 */ | ||
var rate: Int = 0 | ||
|
||
/** 输出设备序号 */ | ||
var audio: Int = 0 | ||
|
||
/** 声音对象 */ | ||
var spVoice:Dispatch? = null | ||
|
||
var ax: ActiveXComponent? = null | ||
|
||
init { | ||
System.setProperty("jacob.dll.path", getResourcesFile("jacob/jacob-1.20-x64.dll").absolutePath ?: "") | ||
ax = ActiveXComponent("Sapi.SpVoice") | ||
spVoice = ax!!.`object` | ||
} | ||
|
||
|
||
/** | ||
* 播放语言 | ||
* @param text 要转换成语言的文本 | ||
*/ | ||
fun speak(text: String) { | ||
try{ | ||
// 设置音量 | ||
Dispatch.put(spVoice,"Volume",Variant(this.volume)) | ||
// 设置速率 | ||
Dispatch.put(spVoice,"Rate",Variant(this.rate)) | ||
// 开始朗读 | ||
Dispatch.call(spVoice,"Speak",Variant(text)) | ||
}catch (exception: Exception) { | ||
println(exception.message) | ||
exception.printStackTrace() | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters