mirror of
https://github.com/neuml/txtai.git
synced 2026-10-12 02:19:52 +00:00
317 KiB
317 KiB
In [44]:
%%capture
!pip install git+https://github.com/neuml/txtai#egg=txtai[pipeline-audio,pipeline-data] onnxruntime-gpu librosa
# Install NLTK
import nltk
nltk.download('averaged_perceptron_tagger_eng')In [45]:
%%capture
from txtai.pipeline import TextToSpeech
# Create text-to-speech model
tts = TextToSpeech()In [46]:
import librosa.display
import matplotlib.pyplot as plt
text = "Text To Speech models have made great strides in quality over the last few years."
# Generate raw waveform speech
speech, rate = tts(text), 22050
# Print waveplot
plt.figure(figsize=(15, 5))
plot = librosa.display.waveshow(speech[0], sr=speech[1])In [47]:
from IPython.display import Audio, display
import os
import soundfile as sf
def play(speech):
# Convert to MP3 to save space
sf.write("speech.wav", speech[0], speech[1])
!ffmpeg -i speech.wav -y -b:a 64 speech.mp3 2> /dev/null
# Play speech
display(Audio(filename="speech.mp3"))
play(speech)In [48]:
from txtai.pipeline import Transcription
# Transcribe files
transcribe = Transcription("openai/whisper-base")
# Print result
transcribe(speech, rate)Out [48]:
'Text to speech models have made great strides in quality over the last few years.'
In [49]:
text = "This is streaming speech generation. It's designed to take output tokens from a streaming LLM. It returns snippets of speech.".split()
for speech, _ in tts(text, stream=True):
print(speech.shape)(32768,) (31488,) (26368,)
In [50]:
# Beginning of The Great Gatsby from Project Gutenberg
# https://www.gutenberg.org/ebooks/64317
text = """
In my younger and more vulnerable years my father gave me some advice
that I've been turning over in my mind ever since.
“Whenever you feel like criticizing anyone,” he told me, “just
remember that all the people in this world haven't had the advantages
that you've had.”
He didn't say any more, but we've always been unusually communicative
in a reserved way, and I understood that he meant a great deal more
than that.
"""
tts = TextToSpeech("neuml/vctk-vits-onnx")
speech = tts(text, speaker=3)
play(speech)In [51]:
%%writefile workflow.yml
summary:
path: sshleifer/distilbart-cnn-12-6
textractor:
join: true
lines: false
minlength: 100
paragraphs: true
sentences: false
texttospeech:
path: neuml/vctk-vits-onnx
workflow:
tts:
tasks:
- action: textractor
task: url
- action: summary
- action: texttospeech
args:
speaker: 15Overwriting workflow.yml
In [52]:
from txtai.app import Application
app = Application("workflow.yml")
speech = list(app.workflow("tts", ["https://en.wikipedia.org/wiki/Natural_language_processing"]))[0]
play(speech)