File size: 1,195 Bytes
eccb33b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import av
import time

apikey = 'jkN9qoC2wChdRZSQH_Sc0i6bznFuFMuXiAjvIWcI5yZ3'
url = 'https://api.eu-gb.text-to-speech.watson.cloud.ibm.com/instances/d2bde643-048b-4240-a609-21ddf49082df'


# Setup Service
authenticator = IAMAuthenticator(apikey)
tts = TextToSpeechV1(authenticator=authenticator)
tts.set_service_url(url)

def get_audio():
    if True:
        
        output_text_file = open('output_text.txt','r')
        frames: List[int] = []
        text = ""
        
        for line in output_text_file.readlines():
            text += str(line)
        if len(text):
            print(">>>>>>>>>>>>>>>>>>>>>>>>",len(text))
            file = 'audio.mp3'
            with open(file, 'wb') as audio_file:
                res = tts.synthesize(text, accept='audio/mp3', voice='en-GB_JamesV3Voice').get_result()
                audio_file.write(res.content)
    #     container = av.open(file)
    #     for frame in container.decode(audio=0):
    #         print("Appending Frames")
    #         frames.append(frame)
    # print(">>>>>> Frame Length: ",len(frames))
    # return frames