File size: 669 Bytes
0e6d852
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import numpy as np
import scipy
from transformers import pipeline


def generate_audio(one_sentence_summary):
    """ Generate an audio from the summary of the abstract of PDF file."""
    synthesiser = pipeline("text-to-speech", "suno/bark-small")
    speech = synthesiser(one_sentence_summary, forward_params={"do_sample": True})
    return speech["audio"], speech["sampling_rate"]

def convert_to_16_bit_wav(data):
    # Based on: https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.write.html
    if data.dtype == np.float32:
        data = data / np.abs(data).max()
        data = data * 32767
        data = data.astype(np.int16)
    return data