-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex4_getText2VoiceStream.py
More file actions
executable file
·59 lines (42 loc) · 1.62 KB
/
ex4_getText2VoiceStream.py
File metadata and controls
executable file
·59 lines (42 loc) · 1.62 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Example 4: TTS - getText2VoiceStream"""
from __future__ import print_function
from ctypes import *
import MicrophoneStream as MS
import gigagenieRPC_pb2
import gigagenieRPC_pb2_grpc
import grpc
import user_auth as UA
HOST = 'openapi.gigagenie.ai'
PORT = 50051
ERROR_HANDLER_FUNC = CFUNCTYPE(None, c_char_p, c_int, c_char_p, c_int, c_char_p)
def py_error_handler(filename, line, function, err, fmt):
dummy_var = 0
c_error_handler = ERROR_HANDLER_FUNC(py_error_handler)
asound = cdll.LoadLibrary('libasound.so')
asound.snd_lib_error_set_handler(c_error_handler)
# TTS : getText2VoiceStream
def getText2VoiceStream(input_text, input_filename):
channel = grpc.secure_channel('{}:{}'.format(HOST, PORT), UA.getCredentials())
stub = gigagenieRPC_pb2_grpc.GigagenieStub(channel)
message = gigagenieRPC_pb2.reqText()
message.lang = 0
message.mode = 0
message.text = input_text
output_file = open(input_filename, 'wb')
for response in stub.getText2VoiceStream(message):
if response.HasField("resOptions"):
print("\n\nResVoiceResult: %d" % response.resOptions.resultCd)
if response.HasField("audioContent"):
print("Audio Stream\n\n")
output_file.write(response.audioContent)
output_file.close()
return response.resOptions.resultCd
def main():
output_file = "testtts.wav"
getText2VoiceStream("안녕하세요. 반갑습니다.", output_file)
MS.play_file(output_file)
print(output_file + "이 생성되었으니 파일을 확인바랍니다. \n\n\n")
if __name__ == '__main__':
main()