mirror of
https://github.com/neuml/txtai.git
synced 2026-10-11 21:39:55 +00:00
8.5 KiB
8.5 KiB
In [ ]:
%%capture
!pip install git+https://github.com/neuml/txtai#egg=txtai[pipeline-audio]In [ ]:
import logging
from txtai import Embeddings, RAG
from txtai.pipeline import AudioStream, Microphone, TextToSpeech, Transcription
from txtai.workflow import Workflow, StreamTask, Task
# Enable DEBUG logging
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
# Microphone
microphone = Microphone()
# Transcription
transcribe = Transcription("distil-whisper/distil-large-v3")
# Embeddings database
embeddings = Embeddings()
embeddings.load(provider="huggingface-hub", container="neuml/txtai-wikipedia")
# Define prompt template
template = """
Answer the following question using only the context below. Only include information
specifically discussed. Answer the question without explaining how you found the answer.
question: {question}
context: {context}"""
# Create RAG pipeline
rag = RAG(
embeddings,
"Qwen/Qwen3-4B-Instruct-2507",
system="You are a friendly assistant. You answer questions from users.",
template=template,
context=10
)
# Text to speech
tts = TextToSpeech("neuml/vctk-vits-onnx")
# Audio stream
audiostream = AudioStream()
# Define speech to speech workflow
workflow = Workflow(tasks=[
Task(action=microphone),
Task(action=transcribe, unpack=False),
StreamTask(action=lambda x: rag(x, maxlength=4096, stream=True), batch=True),
StreamTask(action=lambda x: tts(x, stream=True, speaker=15), batch=True),
StreamTask(action=audiostream, batch=True)
])
while True:
print("Waiting for input...")
list(workflow([None]))In [ ]:
%%writefile s2s.yml
# Microphone
microphone:
# Transcription
transcription:
path: distil-whisper/distil-large-v3
# Embeddings database
cloud:
provider: huggingface-hub
container: neuml/txtai-wikipedia
embeddings:
# RAG
rag:
path: "Qwen/Qwen3-4B-Instruct-2507"
system: You are a friendly assistant. You answer questions from users.
template: |
Answer the following question using only the context below. Only include information
specifically discussed. Answer the question without explaining how you found the answer.
question: {question}
context: {context}
context: 10
# TTS
texttospeech:
path: neuml/vctk-vits-onnx
# AudioStream
audiostream:
# Speech to Speech Chat workflow
workflow:
s2s:
tasks:
- microphone
- action: transcription
unpack: False
- task: stream
action: rag
args:
maxlength: 4096
stream: True
batch: True
- task: stream
action: texttospeech
args:
stream: True
speaker: 15
batch: True
- task: stream
action: audiostream
batch: TrueIn [ ]:
from txtai import Application
app = Application("s2s.yml")
while True:
print("Waiting for input...")
list(app.workflow("s2s", [None]))