Skip to content

Instantly share code, notes, and snippets.

@2rs2ts
Last active October 24, 2022 23:33
Show Gist options
  • Save 2rs2ts/481a1f5b426c36016f71da67998859b4 to your computer and use it in GitHub Desktop.
Save 2rs2ts/481a1f5b426c36016f71da67998859b4 to your computer and use it in GitHub Desktop.
VoiceForge download script, requires python 3 and requests
#! /usr/bin/env python3
# Copyright 2019 2rs2ts
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import argparse
import re
import requests
import sys
import time
BASE_URL = 'https://www.voiceforge.com'
def parse_args():
parser = argparse.ArgumentParser(description='Download VoiceForge audio')
parser.add_argument('-c', '--voice', required=True, default='Wiseguy', help='name of voice to use. (Garfield is Wiseguy, Jon is JerkFace)')
parser.add_argument('-t', '--text', required=True, default='Time to kick Odie off the table', help='text to speak')
parser.add_argument('-f', '--format', required=True, default='mp3', choices=('mp3', 'ogg'), help='audio format')
parser.add_argument('-o', '--output', required=True, help='path to output file to, - is stdout')
return parser.parse_args()
def get_session_cookies():
r = requests.get(BASE_URL + '/demo')
return r.cookies
def get_audio_rl(voice, text, format, cookies):
# voiceforge's js uses Date.getTime()
p = {'voice': voice, 'voiceText': text, 'createTime': int(time.time() * 1000)}
r = requests.get(BASE_URL + '/demos/createAudio.php', params=p, cookies=cookies)
expr = r'"(?P<rl>[/\w\.]+\.{fmt})"'.format(fmt=format)
match = re.search(expr, r.text)
if not match:
raise Exception("Couldn't find URL in {}".format(r.text))
return match.group('rl')
def download_audio(output, rl, cookies):
r = requests.get(BASE_URL + rl, cookies=cookies)
if not r.content:
raise Exception("Didn't get an audio download in {}".format(r))
if output == '-':
sys.stdout.write(r.content)
else:
with open(output, 'wb') as o:
o.write(r.content)
def main():
args = parse_args()
cookies = get_session_cookies()
rl = get_audio_rl(voice=args.voice, text=args.text, format=args.format, cookies=cookies)
download_audio(output=args.output, rl=rl, cookies=cookies)
if __name__ == "__main__":
main()
@danielbup
Copy link

how do i use it tho? and does it even work anymore?

@2rs2ts
Copy link
Author

2rs2ts commented Oct 24, 2022

@danielbup https://opensourceoptions.com/blog/how-to-run-python-scripts-from-the-command-line/

However it does not work anymore since they got rid of their web version, as far as I can tell. It's now a mobile app only. Maybe you can run it in an Android emulator if you want to try automating usage of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment