File size: 690 Bytes
9b0d264
 
4bb9300
 
9b0d264
0fb503b
9b0d264
4bb9300
 
 
 
 
0fb503b
4bb9300
5e83c71
9b0d264
0fb503b
06fe464
0fb503b
06fe464
4bb9300
0fb503b
4bb9300
 
0fb503b
06fe464
4bb9300
9b0d264
 
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
import logging

import torch
import soundfile as sf

from io import BytesIO
from .config import pipe_tts

SAMPLING_RATE = 16000

class T2A:
    def __init__(self, input_text: str):
        self.output_model = pipe_tts(input_text)

    def get_audio(self):
        try:
            synth = self.output_model["audio"][0]

            print(f"synth : {synth}")

            with BytesIO() as buffer:
                sf.write(buffer, synth, SAMPLING_RATE, format='wav')
                output = buffer.getvalue() # bytes

            print(f"output : {output}, type : {type(output)}")

            return output
        except Exception as e:
            logging.error(f"Raised an error : {e}")