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