Spaces:
Running
Running
Update transcription.py
Browse files- transcription.py +8 -4
transcription.py
CHANGED
@@ -17,13 +17,18 @@ class TranscriptionMaker():
|
|
17 |
def create_transcription(self,audio_directory):
|
18 |
results = []
|
19 |
#ディレクトリ内のファイルを全て取得
|
|
|
|
|
20 |
audio_files = os.listdir(audio_directory)
|
21 |
for audio_file in audio_files:
|
22 |
if os.path.splitext(audio_file)[-1].lower() != '.wav':
|
23 |
continue
|
24 |
audio_path = os.path.join(audio_directory, audio_file)
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
for segment in segments:
|
28 |
results.append({
|
29 |
"start": segment.start,
|
@@ -39,5 +44,4 @@ class TranscriptionMaker():
|
|
39 |
except OSError as e:
|
40 |
print(f"Error writing transcription file: {e}")
|
41 |
raise
|
42 |
-
return output_file
|
43 |
-
|
|
|
17 |
def create_transcription(self,audio_directory):
|
18 |
results = []
|
19 |
#ディレクトリ内のファイルを全て取得
|
20 |
+
if not os.path.isdir(audio_directory):
|
21 |
+
raise ValueError(f"The specified path is not a valid directory: {audio_directory}")
|
22 |
audio_files = os.listdir(audio_directory)
|
23 |
for audio_file in audio_files:
|
24 |
if os.path.splitext(audio_file)[-1].lower() != '.wav':
|
25 |
continue
|
26 |
audio_path = os.path.join(audio_directory, audio_file)
|
27 |
+
try:
|
28 |
+
segments,info = list(self.model.transcribe(audio_path))
|
29 |
+
except Exception as e:
|
30 |
+
print(f"Error transcripting file {audio_path}: {e}")
|
31 |
+
raise
|
32 |
for segment in segments:
|
33 |
results.append({
|
34 |
"start": segment.start,
|
|
|
44 |
except OSError as e:
|
45 |
print(f"Error writing transcription file: {e}")
|
46 |
raise
|
47 |
+
return output_file
|
|