Skip to content

Commit 4f896ae

Browse files
committed
Added new list command to CLI
1 parent 4545e1f commit 4f896ae

File tree

6 files changed

+75
-10
lines changed

6 files changed

+75
-10
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Neural Noise is an AI-powered podcast studio that uses multiple AI agents workin
88

99
## Examples
1010

11-
| Source | Neural Noise |
12-
| ------ | ------------ |
13-
| [TikTok owner sacks intern for sabotaging AI project](https://www.bbc.com/news/articles/c7v62gg49zro) | <video src="https://github.com/user-attachments/assets/e79982c8-bb58-4395-8bce-aa25eee0b5c5" /> |
11+
| Source | Neural Noise |
12+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
13+
| [TikTok owner sacks intern for sabotaging AI project](https://www.bbc.com/news/articles/c7v62gg49zro) | <video src="https://github.com/user-attachments/assets/e79982c8-bb58-4395-8bce-aa25eee0b5c5" /> |
1414
| [Before you buy a domain name, first check to see if it's haunted](https://www.bryanbraun.com/2024/10/25/before-you-buy-a-domain-name-first-check-to-see-if-its-haunted/) | <video src="https://github.com/user-attachments/assets/53fabfd9-5422-431a-9ed5-6d9dd58de92e" /> |
15-
| [Linus Torvalds Comments On The Russian Linux Maintainers Being Delisted](https://www.phoronix.com/news/Linus-Torvalds-Russian-Devs) | <video src="https://github.com/user-attachments/assets/85671e26-ae06-4152-b6a2-e5aa6916e5b0" /> |
15+
| [Linus Torvalds Comments On The Russian Linux Maintainers Being Delisted](https://www.phoronix.com/news/Linus-Torvalds-Russian-Devs) | <video src="https://github.com/user-attachments/assets/85671e26-ae06-4152-b6a2-e5aa6916e5b0" /> |
1616

1717
## Objective
1818

@@ -62,7 +62,7 @@ To run the Neural Noise application first make sure that you create a configurat
6262
Then you can run the application with:
6363
6464
```
65-
nn <url|filepath> --name <name> --config-path <config>
65+
nn new <url|filepath> --name <name> --config-path <config>
6666
```
6767
6868
## Want to edit the generated script?

config/config_elevenlabs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
}
3737
}
3838
}
39-
}
39+
}

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "neuralnoise"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
description = "An AI-powered podcast studio that uses multiple AI agents working together."
55
authors = [
66
{ name = "Leonardo Piñeyro", email = "[email protected]" }
@@ -43,6 +43,7 @@ dependencies = [
4343
"pymupdf>=1.24.12",
4444
"python-dotenv>=1.0.1",
4545
"requests>=2.32.3",
46+
"tabulate>=0.9.0",
4647
"typer>=0.12.5",
4748
"youtube-transcript-api>=0.6.2",
4849
]

src/neuralnoise/cli.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from pathlib import Path
2-
32
import typer
43
from dotenv import load_dotenv
4+
from pydub import AudioSegment
5+
from tabulate import tabulate
6+
from pydub.exceptions import CouldntDecodeError
57

68
from neuralnoise.extract import extract_content
79
from neuralnoise.studio import create_podcast_episode
@@ -49,5 +51,56 @@ def new(
4951
typer.echo(f"Podcast generation complete. Output saved to {output_dir}")
5052

5153

54+
def get_audio_length(file_path: Path) -> float:
55+
"""Get the length of an audio file in seconds."""
56+
try:
57+
audio = AudioSegment.from_file(file_path)
58+
return len(audio) / 1000 # Convert milliseconds to seconds
59+
except CouldntDecodeError:
60+
typer.echo(f"Error: Couldn't decode audio file {file_path}")
61+
return -1.0
62+
63+
64+
@app.command("list")
65+
def list_episodes():
66+
"""
67+
List all generated podcast episodes stored in the 'output' folder,
68+
including their audio file length in minutes. Episodes with invalid audio files are filtered out.
69+
"""
70+
output_dir = Path("output")
71+
if not output_dir.exists():
72+
typer.echo("No episodes found. The 'output' folder does not exist.")
73+
return
74+
75+
episodes = [d for d in output_dir.iterdir() if d.is_dir()]
76+
77+
if not episodes:
78+
typer.echo("No episodes found in the 'output' folder.")
79+
return
80+
81+
episode_data = []
82+
for episode in sorted(episodes):
83+
audio_files = list(episode.glob("*.wav")) + list(episode.glob("*.mp3"))
84+
if audio_files:
85+
audio_file = audio_files[0] # Take the first audio file found
86+
length_seconds = get_audio_length(audio_file)
87+
if length_seconds != -1: # Filter out invalid audio files
88+
length_minutes = length_seconds / 60 # Convert seconds to minutes
89+
episode_data.append(
90+
[episode.name, audio_file.name, f"{length_minutes:.2f}"]
91+
)
92+
else:
93+
episode_data.append([episode.name, "No audio file", "N/A"])
94+
95+
if not episode_data:
96+
typer.echo("No valid episodes found.")
97+
return
98+
99+
headers = ["Episode", "Audio File", "Length (minutes)"]
100+
table = tabulate(episode_data, headers=headers, tablefmt="grid")
101+
typer.echo("Generated podcast episodes:")
102+
typer.echo(table)
103+
104+
52105
if __name__ == "__main__":
53106
app()

src/neuralnoise/studio/create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def create_podcast_episode(
7474
name: str,
7575
content: str,
7676
config_file: str | Path,
77-
format: Literal["wav", "mp3", "ogg"] = "ogg",
77+
format: Literal["wav", "mp3", "ogg"] = "wav",
7878
only_script: bool = False,
7979
):
8080
# Create output directory

uv.lock

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)