-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_to_speech.py
41 lines (29 loc) · 1.11 KB
/
text_to_speech.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import clr
import time
def connect_to_editor():
_editor_dir = os.environ['ProgramW6432'] + '\\AI\\AIVoice\\AIVoiceEditor\\'
if not os.path.isfile(_editor_dir + 'AI.Talk.Editor.Api.dll'):
print("A.I.VOICE Editor not found.")
exit()
clr.AddReference(_editor_dir + "AI.Talk.Editor.Api")
from AI.Talk.Editor.Api import TtsControl, HostStatus
tts_control = TtsControl()
host_name = tts_control.GetAvailableHostNames()[0]
tts_control.Initialize(host_name)
if tts_control.Status == HostStatus.NotRunning:
tts_control.StartHost()
tts_control.Connect()
host_version = tts_control.Version
print(f"Connected to {host_name} (v{host_version}) .")
return tts_control
def disconnect_from_editor(tts_control):
host_name = tts_control.GetAvailableHostNames()[0]
host_version = tts_control.Version
tts_control.Disconnect()
print(f"Disconnected from {host_name} (v{host_version}) .")
def speech(tts_control, text):
tts_control.Text = text
play_time = tts_control.GetPlayTime()
tts_control.Play()
time.sleep((play_time + 500) / 1000)