Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Conditionally import soundfile

davidmezzetti8b7c8f719dce
diff --git a/src/python/txtai/pipeline/transcription.py b/src/python/txtai/pipeline/transcription.py
index 38176648..9c59f64b 100644
--- a/src/python/txtai/pipeline/transcription.py
+++ b/src/python/txtai/pipeline/transcription.py
@@ -2,7 +2,12 @@
Transcription module
"""
-import soundfile as sf
+try:
+ import soundfile as sf
+
+ SOUNDFILE = True
+except (ImportError, OSError):
+ SOUNDFILE = False
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
@@ -30,6 +35,9 @@ class Transcription(HFModel):
# Call parent constructor
super().__init__(path, quantize, gpu, batch)
+ if not SOUNDFILE:
+ raise ImportError("SoundFile library not installed or libsndfile not found")
+
# load model and processor
self.model = Wav2Vec2ForCTC.from_pretrained(self.path)
self.processor = Wav2Vec2Processor.from_pretrained(self.path)