Spaces:
Running
Running
File size: 1,091 Bytes
28d0c5f |
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 |
import models
import soundfile as sf
import json
import AIModels
#from flask import Response
import utilsFileIO
import os
import base64
sampling_rate = 16000
model_TTS_lambda = AIModels.NeuralTTS(models.getTTSModel('de'), sampling_rate)
def lambda_handler(event, context):
body = json.loads(event['body'])
text_string = body['value']
linear_factor = 0.2
audio = model_TTS_lambda.getAudioFromSentence(
text_string).detach().numpy()*linear_factor
random_file_name = utilsFileIO.generateRandomString(20)+'.wav'
sf.write('./'+random_file_name, audio, 16000)
with open(random_file_name, "rb") as f:
audio_byte_array = f.read()
os.remove(random_file_name)
return {
'statusCode': 200,
'headers': {
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
},
'body': json.dumps(
{
"wavBase64": str(base64.b64encode(audio_byte_array))[2:-1],
},
)
}
|