bournemouth-forced-aligner 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ """
2
+ Bournemouth Forced Aligner - Phoneme-level timestamp extraction from audio using CUPE models.
3
+
4
+ URL: https://github.com/tabahi/bournemouth-forced-aligner
5
+ """
6
+
7
+ __version__ = "0.1.0"
8
+
9
+ from .core import PhonemeTimestampAligner, process_single_clip, process_transcription
10
+
11
+ __all__ = [
12
+ "PhonemeTimestampAligner",
13
+ "process_single_clip",
14
+ "process_transcription",
15
+ "__version__"
16
+ ]
@@ -0,0 +1,121 @@
1
+ import click
2
+ import os
3
+ from .core import PhonemeTimestampAligner
4
+
5
+ __version__ = "1.0.0" # Set your version here
6
+
7
+ @click.command()
8
+ @click.argument('audio_path', type=click.Path(exists=True))
9
+ @click.argument('srt_path', type=click.Path(exists=True))
10
+ @click.argument('output_path', type=click.Path())
11
+ @click.option('--model', default="en_libri1000_uj01d_e199_val_GER=0.2307.ckpt",
12
+ help='CUPE model name from HuggingFace')
13
+ @click.option('--lang', default='en-us',
14
+ help='Language code for phonemization (e.g., en-us, es, fr)')
15
+ @click.option('--device', default='cpu',
16
+ help='Device for inference (cpu/cuda)')
17
+ @click.option('--embeddings', type=click.Path(),
18
+ help='Path to save phoneme embeddings (.pt file)')
19
+ @click.option('--duration-max', default=10.0, type=float,
20
+ help='Maximum segment duration in seconds')
21
+ @click.option('--debug/--no-debug', default=False,
22
+ help='Enable detailed debug output')
23
+ @click.option('--boost-targets/--no-boost-targets', default=True,
24
+ help='Enable target phoneme boosting for better alignment')
25
+ @click.version_option(__version__, '--version', '-v', message='%(version)s')
26
+ def main(audio_path, srt_path, output_path, model, lang, device, embeddings,
27
+ duration_max, debug, boost_targets):
28
+ """
29
+ Bournemouth Forced Aligner - Extract phoneme timestamps from audio.
30
+
31
+ AUDIO_PATH: Path to audio file (.wav, .mp3, etc.)
32
+ SRT_PATH: Path to SRT file in JSON format
33
+ OUTPUT_PATH: Path for output timestamps (.json)
34
+
35
+ Example:
36
+ balign audio.wav transcription.srt output.json --embeddings embeddings.pt
37
+ """
38
+
39
+ # Validate inputs
40
+ if not os.path.exists(audio_path):
41
+ click.echo(f"āœ— Audio file not found: {audio_path}", err=True)
42
+ raise click.Abort()
43
+
44
+ if not os.path.exists(srt_path):
45
+ click.echo(f"āœ— SRT file not found: {srt_path}", err=True)
46
+ raise click.Abort()
47
+
48
+ # Create output directory if needed
49
+ os.makedirs(os.path.dirname(os.path.abspath(output_path)), exist_ok=True)
50
+
51
+ if debug:
52
+ click.echo("šŸš€ Bournemouth Forced Aligner")
53
+ click.echo(f"šŸ“ Audio: {audio_path}")
54
+ click.echo(f"šŸ“„ SRT: {srt_path}")
55
+ click.echo(f"šŸ’¾ Output: {output_path}")
56
+ click.echo(f"šŸ·ļø Language: {lang}")
57
+ click.echo(f"šŸ–„ļø Device: {device}")
58
+ click.echo(f"šŸŽÆ Model: {model}")
59
+ if embeddings:
60
+ click.echo(f"🧮 Embeddings: {embeddings}")
61
+ click.echo("-" * 50)
62
+
63
+ try:
64
+ # Initialize aligner
65
+ if debug:
66
+ click.echo("šŸ”§ Initializing aligner...")
67
+
68
+ aligner = PhonemeTimestampAligner(
69
+ model_name=model,
70
+ lang=lang,
71
+ duration_max=duration_max,
72
+ device=device,
73
+ boost_targets=boost_targets
74
+ )
75
+
76
+ if debug:
77
+ click.echo("āœ… Aligner initialized successfully")
78
+ click.echo("šŸŽµ Processing audio...")
79
+
80
+ # Process audio
81
+ result = aligner.process_srt_file(
82
+ srt_path=srt_path,
83
+ audio_path=audio_path,
84
+ ts_out_path=output_path,
85
+ vspt_path=embeddings,
86
+ extract_embeddings=bool(embeddings),
87
+ debug=debug
88
+ )
89
+
90
+ if result:
91
+ click.echo(f"āœ… Timestamps extracted to {output_path}")
92
+
93
+ # Show summary
94
+ total_segments = len(result.get('segments', []))
95
+ total_phonemes = sum(len(seg.get('phoneme_ts', [])) for seg in result.get('segments', []))
96
+
97
+ click.echo(f"šŸ“Š Processed {total_segments} segments with {total_phonemes} phonemes")
98
+
99
+ if embeddings:
100
+ click.echo(f"🧮 Embeddings saved to {embeddings}")
101
+
102
+ else:
103
+ click.echo("āœ— Processing failed - no output generated", err=True)
104
+ raise click.Abort()
105
+
106
+ except KeyboardInterrupt:
107
+ click.echo("\nā¹ļø Processing interrupted by user", err=True)
108
+ raise click.Abort()
109
+
110
+ except Exception as e:
111
+ click.echo(f"āœ— Error during processing: {e}", err=True)
112
+ if debug:
113
+ import traceback
114
+ click.echo(traceback.format_exc(), err=True)
115
+ raise click.Abort()
116
+
117
+ if debug:
118
+ click.echo("šŸŽ‰ Processing completed successfully!")
119
+
120
+ if __name__ == '__main__':
121
+ main()