Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 18 additions & 42 deletions hns/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import pyperclip
import sounddevice as sd
from rich.console import Console
from rich.progress import Progress, SpinnerColumn, TextColumn, TimeElapsedColumn

console = Console(stderr=True)
stdout_console = Console()
Expand Down Expand Up @@ -72,7 +71,7 @@ def update_timer():
time_str = format_duration(elapsed)
# Overwrite the same line
console.print(
f"🎤 [bold blue]Recording {time_str}... Press Enter to stop[/bold blue]", end="\r"
f"🎤 [bold blue]Recording ...... {time_str} Press Enter to stop[/bold blue]", end="\r"
)
time.sleep(1)

Expand Down Expand Up @@ -205,15 +204,6 @@ def transcribe(self, audio_source: Union[Path, str], show_progress: bool = True)
transcribe_kwargs["language"] = self.language

try:
audio_duration = self._get_audio_duration(audio_source) if show_progress else None

if show_progress:
if audio_duration:
duration_str = format_duration(audio_duration)
console.print(f"🔄 [bold blue]Transcribing {duration_str} of audio...[/bold blue]")
else:
console.print("🔄 [bold blue]Transcribing audio...[/bold blue]")

start_time = time.time()

if show_progress:
Expand Down Expand Up @@ -243,30 +233,15 @@ def transcribe_worker():
worker_thread.daemon = True
worker_thread.start()

with Progress(
SpinnerColumn(),
TextColumn("[bold blue]Processing audio..."),
TimeElapsedColumn(),
transient=False,
console=console,
) as progress:
task = progress.add_task("Analyzing speech patterns", total=None)
# Simple progress display with elapsed timer
while not transcription_complete.is_set():
elapsed = time.time() - start_time
time_str = format_duration(elapsed)
console.print(f"🔄 [bold blue]Transcribing ... {time_str}[/bold blue]", end="\r")
time.sleep(1)

while not transcription_complete.is_set():
elapsed = time.time() - start_time
if audio_duration and elapsed > 0:
# Rough estimation: transcription usually takes 10-30% of audio duration
estimated_progress = min(95, (elapsed / (audio_duration * 0.2)) * 100)
progress.update(
task,
description=f"[bold blue]Processing (~{estimated_progress:.0f}% estimated)[/bold blue]",
)
else:
progress.update(
task, description=f"[bold blue]Processing ({elapsed:.1f}s elapsed)[/bold blue]"
)

time.sleep(0.1) # Update every 100ms
# Print a new line
console.print("")

result_type, result_data = progress_queue.get()
if result_type == "error":
Expand Down Expand Up @@ -299,13 +274,9 @@ def list_models(cls):
console.print(" [dim]export HNS_LANG=<language-code> # e.g., en, es, fr[/dim]")


def copy_to_clipboard(text: str, elapsed_time: Optional[float] = None):
def copy_to_clipboard(text: str):
pyperclip.copy(text)
if elapsed_time:
console.print(f"✅ [bold green]Transcribed and copied to clipboard in {elapsed_time:.1f}s![/bold green]")
else:
console.print("✅ [bold green]Transcribed and copied to clipboard![/bold green]")
stdout_console.print(text)
console.print("✅ [bold green]Copied to clipboard![/bold green]")


@click.command()
Expand Down Expand Up @@ -334,9 +305,14 @@ def main(sample_rate: int, channels: int, list_models: bool, language: Optional[
recorder = AudioRecorder(sample_rate, channels)
audio_file_path = recorder.record()
transcriber = WhisperTranscriber(language=language)
transcription, elapsed_time = transcriber.transcribe(audio_file_path, show_progress=True)
transcription, _ = transcriber.transcribe(audio_file_path, show_progress=True)

try:
copy_to_clipboard(transcription)
except Exception as e:
console.print(f"⚠️ [bold yellow]Failed to copy to clipboard: {e}[/bold yellow]")

copy_to_clipboard(transcription, elapsed_time)
stdout_console.print(transcription)

except (RuntimeError, ValueError) as e:
console.print(f"❌ [bold red]{e}[/bold red]")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "hns"
version = "1.0.6"
version = "1.0.7"
description = "A simple, privacy-focused speech-to-text CLI tool"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.