Merge pull request #4 from flypunk/add-speed-arg

Add a speed argument
This commit is contained in:
Claudio Santini 2025-01-16 10:11:50 +01:00 committed by GitHub
commit 019afef1d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View file

@ -41,6 +41,13 @@ Use `-l` option to specify the language, available language codes are:
🇺🇸 `en-us`, 🇬🇧 `en-gb`, 🇫🇷 `fr-fr`, 🇯🇵 `ja`, 🇰🇷 `kr` and 🇨🇳 `cmn`.
## Speed
By default the audio is generated using a normal speed, but you can make it up to twice slower or faster by specifying a speed argument between 0.5 to 2.0:
```bash
audiblez book.epub -l en-gb -v af_sky -s 1.5
```
## Supported Voices
Use `-v` option to specify the voice:
available voices are `af`, `af_bella`, `af_nicole`, `af_sarah`, `af_sky`, `am_adam`, `am_michael`, `bf_emma`, `bf_isabella`, `bm_george`, `bm_lewis`.

View file

@ -21,7 +21,7 @@ from pydub import AudioSegment
from pick import pick
def main(kokoro, file_path, lang, voice, pick_manually):
def main(kokoro, file_path, lang, voice, pick_manually, speed):
filename = Path(file_path).name
with warnings.catch_warnings():
book = epub.read_epub(file_path)
@ -59,7 +59,7 @@ def main(kokoro, file_path, lang, voice, pick_manually):
if i == 1:
text = intro + '.\n\n' + text
start_time = time.time()
samples, sample_rate = kokoro.create(text, voice=voice, speed=1.0, lang=lang)
samples, sample_rate = kokoro.create(text, voice=voice, speed=speed, lang=lang)
sf.write(f'{chapter_filename}', samples, sample_rate)
end_time = time.time()
delta_seconds = end_time - start_time
@ -179,11 +179,12 @@ def cli_main():
parser.add_argument('-v', '--voice', default=default_voice, help=f'Choose narrating voice: {voices_str}')
parser.add_argument('-p', '--pick', default=False, help=f'Manually select which chapters to read in the audiobook',
action='store_true')
parser.add_argument('-s', '--speed', default=1.0, help=f'Set speed from 0.5 to 2.0',type=float)
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
main(kokoro, args.epub_file_path, args.lang, args.voice, args.pick)
main(kokoro, args.epub_file_path, args.lang, args.voice, args.pick, args.speed)
if __name__ == '__main__':