### Full FactsShortEngine Example Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/facts-short-engine.mdx A comprehensive example demonstrating the setup and usage of FactsShortEngine. This includes setting API keys, adding remote assets, configuring a voice module, initializing the engine, generating content, and retrieving the video output path. Ensure all asset names used in initialization match those added to the AssetDatabase. ```python from shortGPT.config.api_db import ApiKeyManager, ApiProvider from shortGPT.config.asset_db import AssetDatabase, AssetType from shortGPT.engine.facts_short_engine import FactsShortEngine from shortGPT.config.languages import Language from shortGPT.audio.edge_voice_module import EdgeTTSVoiceModule, EDGE_TTS_VOICENAME_MAPPING # Set API Keys ApiKeyManager.set_api_key(ApiProvider.OPENAI, "your_openai_key") # Add Assets AssetDatabase.add_remote_asset("minecraft background cube", AssetType.BACKGROUND_VIDEO, "https://www.youtube.com/watch?v=Pt5_GSKIWQM") AssetDatabase.add_remote_asset('chill music', AssetType.BACKGROUND_MUSIC, "https://www.youtube.com/watch?v=uUu1NcSHg2E") # Configure the Voice Module voice_name = EDGE_TTS_VOICENAME_MAPPING[Language.GERMAN]['male'] voice_module = EdgeTTSVoiceModule(voice_name) # Configure Content Engine facts_video_topic = "Interesting scientific facts from the 19th century" content_engine = FactsShortEngine(voice_module=voice_module, facts_type=facts_video_topic, background_video_name="minecraft background cube", # <--- use the same name you saved in the AssetDatabase background_music_name='chill music', # <--- use the same name you saved in the AssetDatabase num_images=5, # If you don't want images in your video, put 0 or None language=Language.GERMAN) # Generate Content for step_num, step_logs in content_engine.makeContent(): print(f" {step_logs}") # Get Video Output Path print(content_engine.get_video_output_path()) ``` -------------------------------- ### Install FFmpeg Source: https://github.com/rayventura/shortgpt/blob/stable/installation-notes.md Install the compiled FFmpeg binaries and libraries on the system. ```bash sudo make install ``` -------------------------------- ### Install ShortGPT Library (Bash) Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/how-to-install.mdx Use this command to install or upgrade the ShortGPT library. Ensure Python and pip are installed. ```bash pip install --upgrade shortgpt ``` -------------------------------- ### Start ShortGPT Application Source: https://github.com/rayventura/shortgpt/blob/stable/docs/README.md Execute this command within the project directory to start the ShortGPT application. A browser window will open to the documentation. ```bash yarn start ``` -------------------------------- ### Full ContentVideoEngine Example Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/content-video-engine.mdx A comprehensive example demonstrating setting API keys, adding assets, configuring the voice module, preparing a script, initializing the ContentVideoEngine, generating content, and retrieving the video output path. ```python from shortGPT.config.api_db import ApiKeyManager, ApiProvider from shortGPT.config.asset_db import AssetDatabase, AssetType from shortGPT.engine.content_video_engine import ContentVideoEngine from shortGPT.config.languages import Language from shortGPT.audio.edge_voice_module import EdgeTTSVoiceModule, EDGE_TTS_VOICENAME_MAPPING # Set API Keys ApiKeyManager.set_api_key(ApiProvider.OPENAI, "your_openai_key") ApiKeyManager.set_api_key(ApiProvider.PEXELS, "your_pexels_key") # Add Assets AssetDatabase.add_remote_asset('chill music', AssetType.BACKGROUND_MUSIC, "https://www.youtube.com/watch?v=uUu1NcSHg2E") # Configure the Voice Module voice_name = EDGE_TTS_VOICENAME_MAPPING[Language.SPANISH]['male'] voice_module = EdgeTTSVoiceModule(voice_name) # Prepare the script script = "La inteligencia artificial (IA) está revolucionando nuestro mundo de manera sorprendente. Los robots y asistentes virtuales nos ayudan en nuestras tareas diarias y simplifican nuestra vida. En la medicina, la IA permite diagnósticos más precisos y avances en tratamientos. En la industria automotriz, los vehículos autónomos están cambiando la forma en que nos desplazamos. Sin embargo, surgen interrogantes sobre el impacto en el empleo y la ética de su uso. A pesar de los desafíos, la IA promete un futuro emocionante y lleno de posibilidades. ¿Estamos preparados para abrazar este avance tecnológico?" # Configure Content Engine content_engine = ContentVideoEngine(voice_module, script, background_music_name='chill music', language=Language.SPANISH) # Generate Content for step_num, step_logs in content_engine.makeContent(): print(f" {step_logs}") # Get Video Output Path print(content_engine.get_video_output_path()) ``` -------------------------------- ### Full ContentTranslationEngine Example Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/content-translation-engine.mdx A complete example demonstrating how to set up API keys, configure a voice module, initialize the ContentTranslationEngine, generate translated content, and retrieve the output path. This example uses EdgeTTS for voice generation and translates content to Spanish. ```python from shortGPT.config.api_db import ApiKeyManager, ApiProvider from shortGPT.engine.content_translation_engine import ContentTranslationEngine from shortGPT.config.languages import Language from shortGPT.audio.edge_voice_module import EdgeTTSVoiceModule, EDGE_TTS_VOICENAME_MAPPING # Set API Keys ApiKeyManager.set_api_key(ApiProvider.OPENAI, "your_openai_key") ApiKeyManager.set_api_key(ApiProvider.ELEVEN_LABS, "your_eleven_labs_key") # Configure the Voice Module voice_name = EDGE_TTS_VOICENAME_MAPPING[Language.SPANISH]['male'] voice_module = EdgeTTSVoiceModule(voice_name) # Configure Content Engine src_url = "https://www.youtube.com/watch?v=QQz5hj8y1TE" target_language = Language.SPANISH use_captions = False content_engine = ContentTranslationEngine(voice_module, src_url, target_language, use_captions) # Generate Content for step_num, step_logs in content_engine.makeContent(): print(f" {step_logs}") # Get Video Output Path print(content_engine.get_video_output_path()) ``` -------------------------------- ### Install Dependencies with Yarn Source: https://github.com/rayventura/shortgpt/blob/stable/docs/README.md Run this command in the root of the repository to install project dependencies using Yarn. ```bash yarn install ``` -------------------------------- ### Verify FFmpeg Installation Source: https://github.com/rayventura/shortgpt/blob/stable/installation-notes.md Check if FFmpeg has been installed correctly by displaying its version information. ```bash ffmpeg -version ``` -------------------------------- ### Download and Install Python 3.10.3 Source: https://github.com/rayventura/shortgpt/blob/stable/installation-notes.md Download, extract, configure, and install Python version 3.10.3 with optimizations enabled. ```bash wget https://www.python.org/ftp/python/3.10.3/Python-3.10.3.tgz tar xzf Python-3.10.3.tgz cd Python-3.10.3 ./configure --enable-optimizations make install ``` -------------------------------- ### Install FFmpeg on Ubuntu/Debian (Bash) Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/how-to-install.mdx Install FFmpeg on Ubuntu or Debian-based systems using the apt package manager. This is a required dependency for ShortGPT. ```bash sudo apt-get install ffmpeg ``` -------------------------------- ### Install FFmpeg on macOS (Bash) Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/how-to-install.mdx Install FFmpeg on macOS using the Homebrew package manager. This is a required dependency for ShortGPT. ```bash brew install ffmpeg ``` -------------------------------- ### Install FFmpeg Build Dependencies Source: https://github.com/rayventura/shortgpt/blob/stable/installation-notes.md Install the necessary build dependencies for FFmpeg on Debian 11. ```bash sudo apt update sudo apt build-dep ffmpeg ``` -------------------------------- ### Check Python Version Source: https://github.com/rayventura/shortgpt/blob/stable/installation-notes.md Verify the installed Python version. ```bash python3.10 -V ``` -------------------------------- ### ApiKeyManager Usage Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/api-key-manager.mdx Demonstrates how to set and get API keys using the ApiKeyManager class. ```APIDOC ## ApiKeyManager Class ### Description The `ApiKeyManager` class in ShortGPT is responsible for managing API keys for different service providers. It interacts with a database to store and retrieve these keys. ### Methods #### `set_api_key(key, value)` This method is used to store an API key in the database. - **key** (str or ApiProvider) - Required - The name or enum of the API provider. - **value** (str) - Required - The API key string. #### `get_api_key(key)` This method retrieves an API key from the database. - **key** (str or ApiProvider) - Required - The name or enum of the API provider. ### Request Example (Setting API Keys) ```python from shortGPT.config.api_db import ApiKeyManager, ApiProvider # Using ApiProvider enum ApiKeyManager.set_api_key(ApiProvider.OPENAI, "your_openai_key") ApiKeyManager.set_api_key(ApiProvider.ELEVEN_LABS, "your_eleven_labs_key") # Using string keys ApiKeyManager.set_api_key("OPENAI_API_KEY", "your_openai_key") ApiKeyManager.set_api_key("ELEVENLABS_API_KEY", "your_eleven_labs_key") ``` ### Request Example (Getting API Keys) ```python from shortGPT.config.api_db import ApiKeyManager, ApiProvider # Using ApiProvider enum openai_key = ApiKeyManager.get_api_key(ApiProvider.OPENAI) eleven_labs_key = ApiKeyManager.get_api_key(ApiProvider.ELEVEN_LABS) # Using string keys openai_key_str = ApiKeyManager.get_api_key("OPENAI_API_KEY") eleven_labs_key_str = ApiKeyManager.get_api_key("ELEVENLABS_API_KEY") ``` ### Note The `key` argument can be either a string representing the provider name (e.g., "OPENAI_API_KEY") or an instance of the `ApiProvider` enum (e.g., `ApiProvider.OPENAI`). If an `ApiProvider` enum is used, its `value` attribute will be used as the key internally. ``` -------------------------------- ### Install Debian 11 System Dependencies Source: https://github.com/rayventura/shortgpt/blob/stable/installation-notes.md Update package lists and install essential development libraries required for building software on Debian 11. ```bash sudo apt update && sudo apt upgrade sudo apt install wget git libltdl-dev libjpeg-dev libpng-dev libtiff-dev libgif-dev libfreetype6-dev liblcms2-dev libxml2-dev wget build-essential libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev ``` -------------------------------- ### ContentVideoEngine: Prepare Background Assets Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Prepares background assets by getting voiceover audio duration, trimming the background video, and extracting a random clip. This ensures the background video fits the content. ```python def __prepareBackgroundAssets(self): self.audioDuration = self.videoEditor.get_voice_over_audio_duration(self.audio) self.videoEditor.trim_video(self.background_video_name) self.videoEditor.get_random_clip(self.video_urls) ``` -------------------------------- ### Install Python Package using pip3.10 Source: https://github.com/rayventura/shortgpt/blob/stable/installation-notes.md Command to install a Python package using the specific pip version for Python 3.10. ```bash pip3.10 install ``` -------------------------------- ### Update Dynamic Linker Cache Source: https://github.com/rayventura/shortgpt/blob/stable/installation-notes.md Update the dynamic linker run-time bindings to recognize newly installed libraries. ```bash sudo ldconfig ``` -------------------------------- ### Get Asset Link Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/asset-database.mdx Obtain the source URL or path for an asset. Uses yt-dlp for YouTube media to extract download or direct links. ```python AssetDatabase.get_asset_link('minecraft background cube') ``` -------------------------------- ### Get API Keys using String Keys Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/api-key-manager.mdx Retrieve API keys using string identifiers. This method fetches the keys from the database based on the provided string key. ```python openai_key = ApiKeyManager.get_api_key("OPENAI_API_KEY") eleven_labs_key = ApiKeyManager.get_api_key("ELEVENLABS_API_KEY") ``` -------------------------------- ### Initialize and Use EditingEngine Source: https://context7.com/rayventura/shortgpt/llms.txt Demonstrates initializing the EditingEngine and adding various editing steps like voiceover, background music, cropping, animations, watermarks, captions, and images. The schema can be dumped for debugging, and the video can be rendered. ```python from shortGPT.editing_framework.editing_engine import EditingEngine, EditingStep # Create editing engine editor = EditingEngine() # Add voiceover audio editor.addEditingStep(EditingStep.ADD_VOICEOVER_AUDIO, { 'url': './audio/narration.wav' }) # Add background music with looping editor.addEditingStep(EditingStep.ADD_BACKGROUND_MUSIC, { 'url': './audio/background.mp3', 'loop_background_music': 60, # Duration to loop 'volume_percentage': 0.15 }) # Add background video (cropped to vertical format) editor.addEditingStep(EditingStep.CROP_1920x1080, { 'url': './video/background.mp4' }) # Add subscribe animation editor.addEditingStep(EditingStep.ADD_SUBSCRIBE_ANIMATION, { 'url': 'https://www.youtube.com/watch?v=72WhUT0OM98' }) # Add watermark editor.addEditingStep(EditingStep.ADD_WATERMARK, { 'text': '@MyChannel' }) # Add timed captions captions = [ ((0.0, 2.5), "WELCOME TO OUR VIDEO"), ((2.5, 5.0), "TODAY WE DISCUSS AI"), ((5.0, 8.0), "LET'S GET STARTED") ] for (start, end), text in captions: editor.addEditingStep(EditingStep.ADD_CAPTION_SHORT, { 'text': text, 'set_time_start': start, 'set_time_end': end }) # Add timed images editor.addEditingStep(EditingStep.SHOW_IMAGE, { 'url': './images/ai_robot.png', 'set_time_start': 2.5, 'set_time_end': 5.0 }) # Dump editing schema for debugging schema = editor.dumpEditingSchema() print(schema) # Render final video editor.renderVideo('./output/final_video.mp4', logger=print) ``` -------------------------------- ### ContentShortEngine Initialization Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Initializes the ContentShortEngine with parameters for generating short videos. ```APIDOC ## __init__ ContentShortEngine ### Description Initializes an instance of the `ContentShortEngine` class with the given parameters. It sets the `stepDict` attribute with the specific methods for generating the short video. ### Parameters - **short_type** (str) - Required - Type of short video to generate. - **background_video_name** (str) - Required - Name of the background video. - **background_music_name** (str) - Required - Name of the background music. - **short_id** (str) - Optional - Unique identifier for the short video. - **num_images** (int) - Optional - Number of images to use. - **watermark** (any) - Optional - Watermark to apply. - **language** (Language) - Optional - Language for the content (default: Language.ENGLISH). - **voiceName** (str) - Optional - Name of the voice to use for narration. ``` -------------------------------- ### Initialize ContentShortEngine Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Initializes the ContentShortEngine with parameters for generating a short video. The stepDict is set based on the short_type. ```python def __init__(self, short_type: str, background_video_name: str, background_music_name: str, short_id="", num_images=None, watermark=None, language: Language = Language.ENGLISH, voiceName=""): self.stepDict = self.stepDict[short_type] self.background_video_name = background_video_name self.background_music_name = background_music_name self.short_id = short_id self.num_images = num_images self.watermark = watermark self.language = language self.voiceName = voiceName ``` -------------------------------- ### Instantiate and Run FactsShortEngine in Python Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/getting-started.mdx This Python snippet demonstrates setting up API keys, adding assets, configuring the FactsShortEngine with a voice module (either ElevenLabs or EdgeTTS), and generating video content. Ensure API keys and asset paths are correctly configured before execution. ```python from shortGPT.config.api_db import ApiKeyManager, ApiProvider from shortGPT.config.asset_db import AssetDatabase, AssetType from shortGPT.engine.facts_short_engine import FactsShortEngine from shortGPT.audio.eleven_voice_module import ElevenLabsVoiceModule from shortGPT.config.languages import Language from shortGPT.audio.edge_voice_module import EdgeTTSVoiceModule, EDGE_TTS_VOICENAME_MAPPING # Set API Keys ApiKeyManager.set_api_key(ApiProvider.OPENAI, "your_openai_key") ApiKeyManager.set_api_key(ApiProvider.ELEVEN_LABS, "your_eleven_labs_key") # Add Assets AssetDatabase.add_remote_asset("minecraft background cube", AssetType.BACKGROUND_VIDEO, "https://www.youtube.com/watch?v=Pt5_GSKIWQM") AssetDatabase.add_remote_asset('chill music', AssetType.BACKGROUND_MUSIC, "https://www.youtube.com/watch?v=uUu1NcSHg2E") AssetDatabase.add_local_asset('my_music', AssetType.AUDIO, "./my_music.wav") USE_ELEVEN_LABS = False # Configure the ElevenLabs Voice Module if USE_ELEVEN_LABS: eleven_labs_key = ApiKeyManager.get_api_key(ApiProvider.ELEVEN_LABS) voice_module = ElevenLabsVoiceModule(api_key = eleven_labs_key, voiceName="Chris") else: ## You can also use the EdgeTTS for Free voice synthesis voice_name = EDGE_TTS_VOICENAME_MAPPING[Language.GERMAN]['male'] voice_module = EdgeTTSVoiceModule(voice_name) # Configure Content Engine facts_video_topic = "Interesting scientific facts from the 19th century" content_engine = FactsShortEngine(voiceModule=voice_module, facts_type=facts_video_topic, background_video_name="minecraft background cube", # <--- use the same name you saved in the AssetDatabase background_music_name='chill music', # <--- use the same name you saved in the AssetDatabase num_images=5, # If you don't want images in your video, put 0 or None language=Language.GERMAN) # Generate Content for step_num, step_logs in content_engine.makeContent(): print(f" {step_logs}") # Get Video Output Path print(content_engine.get_video_output_path()) ``` -------------------------------- ### Build and Run ShortGPT Docker Image Source: https://github.com/rayventura/shortgpt/blob/stable/README-Docker.md Build the Docker image for ShortGPT and then run it, mapping the container's port and loading environment variables from the .env file. The application will be accessible on port 31415. ```bash docker build -t short_gpt_docker:latest . docker run -p 31415:31415 --env-file .env short_gpt_docker:latest ``` -------------------------------- ### Configure Environment Variables for ShortGPT Source: https://github.com/rayventura/shortgpt/blob/stable/README-Docker.md Create a .env file to store your API keys for various services used by ShortGPT. Ensure all required keys are present. ```bash GEMINI_API_KEY=put_your_gemini_api_key_here OPENAI_API_KEY=sk-_put_your_openai_api_key_here ELEVENLABS_API_KEY=put_your_eleven_labs_api_key_here PEXELS_API_KEY=put_your_pexels_api_key_here ``` -------------------------------- ### Initialize ContentVideoEngine Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/content-video-engine.mdx Initialize the ContentVideoEngine with a voice module, script, and optional parameters like background music, watermark, format, and language. ```python content_engine = ContentVideoEngine(voice_module, script, background_music_name="", watermark=None, isVerticalFormat=False, language=Language.ENGLISH) ``` -------------------------------- ### Import ApiKeyManager and ApiProvider Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/api-key-manager.mdx Import the necessary classes from the shortGPT.config.api_db module. ```python from shortGPT.config.api_db import ApiKeyManager, ApiProvider ``` -------------------------------- ### Get Eleven API Character Limit Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/api_utils/README.md Retrieves the remaining character limit for a given Eleven API key. Sends a GET request to the Eleven API and extracts usage details from the response. ```python def getCharactersFromKey(key): """Gets the remaining character limit for an API key. Args: key (str): Your Eleven API key. Returns: tuple: A tuple containing the character limit and the number of characters used. """ headers = { "xi-api-key": key } response = requests.get("https://api.elevenlabs.io/v1/user/account", headers=headers) data = response.json() return data['character_limit'], data['character_count'] ``` -------------------------------- ### Import ContentVideoEngine Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/content-video-engine.mdx Import the ContentVideoEngine class from the shortGPT.engine.content_video_engine module. ```python from shortGPT.engine.content_video_engine import ContentVideoEngine ``` -------------------------------- ### Configure FFmpeg Build Options Source: https://github.com/rayventura/shortgpt/blob/stable/installation-notes.md Configure the FFmpeg build with a comprehensive set of recommended options for GPL and various libraries. ```bash ./configure --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-avisynth --enable-libopenmpt --enable-shared --disable-static ``` -------------------------------- ### Initialize FactsShortEngine Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/facts-short-engine.mdx Initialize the FactsShortEngine with required parameters like voice module, facts type, background assets, and language. Ensure voice_module is configured before initialization. ```python content_engine = FactsShortEngine(voice_module, facts_type, background_video_name, background_music_name, num_images=None, watermark=None, language=Language.ENGLISH) ``` -------------------------------- ### Get Asset Duration Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/asset-database.mdx Retrieve the duration in seconds for video or audio assets. Returns None for other asset types. ```python AssetDatabase.get_asset_duration('minecraft background cube') ``` -------------------------------- ### Import AssetDatabase and AssetType Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/asset-database.mdx Import the necessary classes from the shortGPT configuration module. ```python from shortGPT.config.asset_db import AssetDatabase, AssetType ``` -------------------------------- ### Create Reddit Short Engine Source: https://context7.com/rayventura/shortgpt/llms.txt Initializes and uses the RedditShortEngine to generate content and retrieve the video output path. Ensure voice_module is properly initialized before use. ```python content_engine = RedditShortEngine( voiceModule=voice_module, background_video_name="subway surfers", background_music_name='lofi music', num_images=0, # Reddit shorts typically don't use overlay images watermark="@RedditStories", language=Language.ENGLISH ) # Generate content for step_num, step_logs in content_engine.makeContent(): print(f"Step {step_num}: {step_logs}") # Get output path video_path = content_engine.get_video_output_path() print(f"Reddit short saved to: {video_path}") ``` -------------------------------- ### Get API Keys using ApiProvider Enum Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/api-key-manager.mdx Retrieve API keys for specific providers using the ApiProvider enum. The keys are fetched from the database. ```python openai_key = ApiKeyManager.get_api_key(ApiProvider.OPENAI) eleven_labs_key = ApiKeyManager.get_api_key(ApiProvider.ELEVEN_LABS) ``` -------------------------------- ### Get Image URLs with Timestamps Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/editing_utils/README.md Retrieves image URLs and associated text from a list of image-text pairs. It utilizes the searchImageUrlsFromQuery function to find relevant images. ```python getImageUrlsTimed(imageTextPairs) ``` -------------------------------- ### Get Database State as DataFrame Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/asset-database.mdx Retrieve the current state of the asset database as a pandas DataFrame, including asset details like name, type, link, source, and timestamp. ```python AssetDatabase.get_df() ``` -------------------------------- ### Get Edge TTS Voice Names by Language Source: https://context7.com/rayventura/shortgpt/llms.txt Retrieve male and female voice names for English using Edge TTS. This is useful for selecting specific voices for text-to-speech synthesis. ```python english_male = EDGE_TTS_VOICENAME_MAPPING[Language.ENGLISH]['male'] english_female = EDGE_TTS_VOICENAME_MAPPING[Language.ENGLISH]['female'] print(f"English voices: {english_male}, {english_female}") ``` -------------------------------- ### Get Eleven API Voices Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/api_utils/README.md Retrieves a dictionary of available voices from the Eleven API. Requires an API key for authentication. Voices are returned as a dictionary mapping voice names to IDs. ```python def getVoices(api_key=""): """Gets available voices from the Eleven API. Args: api_key (str): Your Eleven API key. Returns: dict: A dictionary of voices, where keys are voice names and values are voice IDs. """ headers = { "xi-api-key": api_key } response = requests.get("https://api.elevenlabs.io/v1/voices", headers=headers) return response.json() ``` -------------------------------- ### Import ContentTranslationEngine Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/content-translation-engine.mdx Import the ContentTranslationEngine class from the shortGPT.engine.content_translation_engine module. ```python from shortGPT.engine.content_translation_engine import ContentTranslationEngine ``` -------------------------------- ### Get Edge TTS Voice Names for Various Languages Source: https://context7.com/rayventura/shortgpt/llms.txt Demonstrates fetching voice names for German, Japanese, and Arabic using Edge TTS. Ensure the Language enum and mapping are correctly configured. ```python german_voice = EDGE_TTS_VOICENAME_MAPPING[Language.GERMAN]['male'] japanese_voice = EDGE_TTS_VOICENAME_MAPPING[Language.JAPANESE]['female'] arabic_voice = EDGE_TTS_VOICENAME_MAPPING[Language.ARABIC]['male'] ``` -------------------------------- ### Get Best Pexels Video Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/api_utils/README.md Retrieves the URL of the best matching video from Pexels based on query, orientation, and previously used videos. Filters and sorts videos by dimensions and duration. Requires `search_videos` function. ```python def getBestVideo(query_string, orientation_landscape=True, used_vids=[]): """Gets the best matching video URL from Pexels. Args: query_string (str): The search query. orientation_landscape (bool): Whether to search for landscape videos. used_vids (list): A list of previously used video IDs to exclude. Returns: str: The URL of the best matching video, or an empty string if none found. """ videos = search_videos(query_string, orientation_landscape) videos = [v for v in videos['videos'] if v['id'] not in used_vids] if not videos: return '' videos.sort(key=lambda v: (v['width'], v['height'], v['duration'])) return videos[-1]['video_files'][0]['link'] ``` -------------------------------- ### Build FFmpeg from Source Source: https://github.com/rayventura/shortgpt/blob/stable/installation-notes.md Compile the FFmpeg source code using multiple processor cores for faster build times. ```bash make -j$(nproc) ``` -------------------------------- ### Get Bing Images by Query Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/api_utils/README.md Retrieves image URLs from the Bing Images API for a given query. Handles request retries and extracts image data from the HTML response. Raises an exception if the request fails or no images are found. ```python def getBingImages(query, retries=5): """Gets image URLs from the Bing Images API. Args: query (str): The search query. retries (int): The number of times to retry the request. Returns: list: A list of dictionaries, where each dictionary contains the URL, width, and height of an image. Raises: Exception: If the request fails or no images are found. """ query = query.replace(' ', '+') for _ in range(retries): response = requests.get(f'https://www.bing.com/images/search?q={query}') if response.status_code == 200: images = _extractBingImages(response.text) if images: return images raise Exception('Could not retrieve images from Bing') ``` -------------------------------- ### Import FactsShortEngine Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/facts-short-engine.mdx Import the FactsShortEngine class from the shortGPT.engine.facts_short_engine module. ```python from shortGPT.engine.facts_short_engine import FactsShortEngine ``` -------------------------------- ### RedditShortEngine Methods Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Methods for generating Reddit short videos, including custom asset preparation. ```APIDOC ## RedditShortEngine Class ### Description This class is used for generating reddit short videos. It extends the `ContentShortEngine` class and overrides the `_generateScript` method to generate the script for the reddit short video. It also adds a custom step for preparing a reddit image. ### Methods #### `_generateScript()` ##### Description Generates the script for the reddit short video by using the `getInterestingRedditQuestion` function from the `reddit_gpt` module. #### `_prepareCustomAssets()` ##### Description Prepares the custom assets for the reddit short video by using the `ingestFlow` method from the `imageEditingEngine` to create a reddit image. #### `_editAndRenderShort()` ##### Description Performs the editing and rendering of the reddit short video by using the `videoEditor` and the editing steps defined in the `stepDict`. ``` -------------------------------- ### Extract Random Video Clip Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/editing_utils/README.md Extracts a random clip of a specified duration from a given video URL and saves it to an output file. Uses ffmpeg and selects a start time between 15% and 85% of the video's duration. Raises an exception on failure. ```python extract_random_clip_from_video(video_url, video_duration, clip_duration, output_file) ``` -------------------------------- ### Create Reddit Story Shorts with RedditShortEngine Source: https://context7.com/rayventura/shortgpt/llms.txt Use RedditShortEngine to create Reddit story-style short videos. It generates fictional Reddit questions and stories, creates a styled Reddit post image, and renders the video with a Reddit format overlay. Set API keys and add background assets. ```python from shortGPT.config.api_db import ApiKeyManager, ApiProvider from shortGPT.config.asset_db import AssetDatabase, AssetType from shortGPT.engine.reddit_short_engine import RedditShortEngine from shortGPT.config.languages import Language from shortGPT.audio.edge_voice_module import EdgeTTSVoiceModule, EDGE_TTS_VOICENAME_MAPPING # Set API keys ApiKeyManager.set_api_key(ApiProvider.OPENAI, "your_openai_key") # Add background assets AssetDatabase.add_remote_asset( "subway surfers", AssetType.BACKGROUND_VIDEO, "https://www.youtube.com/watch?v=example123" ) AssetDatabase.add_remote_asset( 'lofi music', AssetType.BACKGROUND_MUSIC, "https://www.youtube.com/watch?v=example456" ) # Configure voice module voice_name = EDGE_TTS_VOICENAME_MAPPING[Language.ENGLISH]['male'] voice_module = EdgeTTSVoiceModule(voice_name) ``` -------------------------------- ### ContentShortEngine Class Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Engine for generating general content short videos, extending AbstractContentEngine. ```APIDOC ## Class: ContentShortEngine ### Description This class extends `AbstractContentEngine` and is used for generating general content short videos. It implements specific methods for generating a script, temporary audio, timing captions, image search terms, image URLs, choosing background music and video, and preparing assets. ### Attributes - **stepDict** (dict): Maps step numbers to their corresponding methods for generating the short video. ``` -------------------------------- ### Initialize ContentTranslationEngine Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/content-translation-engine.mdx Initialize the ContentTranslationEngine with a voice module, source URL, target language, and an optional captions flag. Ensure the voice_module, src_url, and target_language are properly configured before initialization. ```python content_engine = ContentTranslationEngine(voice_module, src_url, target_language, use_captions=False) ``` -------------------------------- ### Create Short-Form Videos with FactsShortEngine Source: https://context7.com/rayventura/shortgpt/llms.txt Generates short-form vertical videos on any topic using GPT for scripts, synthesized voiceover, and sourced background footage. Requires API keys and asset configuration. ```python from shortGPT.config.api_db import ApiKeyManager, ApiProvider from shortGPT.config.asset_db import AssetDatabase, AssetType from shortGPT.engine.facts_short_engine import FactsShortEngine from shortGPT.config.languages import Language from shortGPT.audio.edge_voice_module import EdgeTTSVoiceModule, EDGE_TTS_VOICENAME_MAPPING # Set API keys ApiKeyManager.set_api_key(ApiProvider.OPENAI, "your_openai_key") # Add background assets AssetDatabase.add_remote_asset( "minecraft background cube", AssetType.BACKGROUND_VIDEO, "https://www.youtube.com/watch?v=Pt5_GSKIWQM" ) AssetDatabase.add_remote_asset( 'chill music', AssetType.BACKGROUND_MUSIC, "https://www.youtube.com/watch?v=uUu1NcSHg2E" ) # Configure voice module voice_name = EDGE_TTS_VOICENAME_MAPPING[Language.ENGLISH]['male'] voice_module = EdgeTTSVoiceModule(voice_name) # Create and configure content engine content_engine = FactsShortEngine( voiceModule=voice_module, facts_type="Interesting scientific facts from the 19th century", background_video_name="minecraft background cube", background_music_name='chill music', num_images=5, # Number of images to overlay (0 or None for no images) watermark="@YourChannel", # Optional channel watermark language=Language.ENGLISH ) # Generate content (yields progress updates) for step_num, step_logs in content_engine.makeContent(): print(f"Step {step_num}: {step_logs}") # Get final video path video_path = content_engine.get_video_output_path() print(f"Video saved to: {video_path}") ``` -------------------------------- ### RedditShortEngine: Prepare Custom Assets Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Prepares custom assets for a Reddit short video by using the ingestFlow method from the imageEditingEngine to create a Reddit-style image. This method overrides the base class implementation. ```python def _prepareCustomAssets(self): self.image = imageEditingEngine.ingestFlow(self.prompt, self.language) self.stepDict["custom_assets"] = self.image ``` -------------------------------- ### Configuration Utilities Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/config/README.md Functions for reading and writing YAML configuration files, and loading local assets. ```APIDOC ## read_yaml_config ### Description Reads and returns the contents of a YAML file as a dictionary. ### Method Not applicable (function) ### Endpoint Not applicable (function) ### Parameters #### Path Parameters - **file_path** (str) - Required - The path to the YAML file to be read. ### Returns - A dictionary containing the contents of the YAML file. ## write_yaml_config ### Description Writes a dictionary to a YAML file. ### Method Not applicable (function) ### Endpoint Not applicable (function) ### Parameters #### Path Parameters - **file_path** (str) - Required - The path to the YAML file to be written. - **data** (dict) - Required - The dictionary to be written to the YAML file. ### Returns None ## load_editing_assets ### Description Loads all local assets from the static-assets folder specified in the yaml_config. ### Method Not applicable (function) ### Endpoint Not applicable (function) ### Returns - A dictionary containing the YAML configuration with updated local assets. ``` -------------------------------- ### RedditShortEngine Class Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Engine for generating reddit short videos, extending ContentShortEngine. ```APIDOC ## Class: RedditShortEngine ### Description This class extends `ContentShortEngine` and is used for generating reddit short videos. It overrides the `_generateScript` method to generate the script for reddit short videos and includes a custom step for preparing a reddit image. ``` -------------------------------- ### ContentVideoEngine: Choose Background Music Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Retrieves the background music URL from the assetStore. The music is selected based on the provided background_music_name. ```python def __chooseBackgroundMusic(self): self.background_music = self.assetStore.get(self.background_music_name) ``` -------------------------------- ### Synchronize Local Assets Source: https://github.com/rayventura/shortgpt/blob/stable/docs/docs/asset-database.mdx Synchronizes the database with local assets found in the /public folder. No action is taken if no assets are found. ```python AssetDatabase.sync_local_assets() ``` -------------------------------- ### ContentVideoEngine Methods Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Methods for generating general content videos. ```APIDOC ## ContentVideoEngine Class ### Description This class is used for generating general content videos. It extends the `AbstractContentEngine` class and adds specific methods for generating temporary audio, speeding up the audio, timing captions, generating video search terms, generating video URLs, choosing background music, and preparing background and custom assets. ### Methods #### `__generateTempAudio()` ##### Description Generates the temporary audio for the content video by using the `voiceModule` to generate a voice from the script. #### `__speedUpAudio()` ##### Description Speeds up the temporary audio to match the duration of the background video. #### `__timeCaptions()` ##### Description Converts the audio to text and then generates captions with time based on the text. #### `__generateVideoSearchTerms()` ##### Description Generates the video search terms by using the timed captions. #### `__generateVideoUrls()` ##### Description Generates the video URLs by using the video search terms and the `getBestVideo` function from the `pexels_api`. #### `__chooseBackgroundMusic()` ##### Description Retrieves the background music URL from the `assetStore` based on the background music name. #### `__prepareBackgroundAssets()` ##### Description Prepares the background assets for the content video by retrieving the voiceover audio duration, trimming the background video, and extracting a random clip from the background video. #### `__prepareCustomAssets()` ##### Description Abstract method that prepares the custom assets for the content short video. This method needs to be implemented by the child classes. #### `__editAndRenderShort()` ##### Description Performs the editing and rendering of the content short video by using the `videoEditor` and the editing steps defined in the `stepDict`. ``` -------------------------------- ### FactsShortEngine Class Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Engine for generating facts short videos, extending ContentShortEngine. ```APIDOC ## Class: FactsShortEngine ### Description This class extends `ContentShortEngine` and is used for generating facts short videos. It overrides the `_generateScript` method to generate the script specifically for facts short videos. ``` -------------------------------- ### RedditShortEngine: Edit and Render Short Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Performs the editing and rendering of the Reddit short video. It uses the videoEditor and the editing steps defined in the stepDict, overriding the base class method. ```python def _editAndRenderShort(self): self.videoEditor.edit_video(self.stepDict) self.videoEditor.render_video() self.video_path = self.videoEditor.video_path ``` -------------------------------- ### ContentVideoEngine Class Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Engine for generating general content videos, extending AbstractContentEngine. ```APIDOC ## Class: ContentVideoEngine ### Description This class extends `AbstractContentEngine` and is used for generating general content videos. It implements specific methods for generating temporary audio, timing captions, video search terms, video URLs, choosing background music, and preparing assets. ``` -------------------------------- ### CoreEditingEngine Class Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/editing_framework/README.md Handles the core generation of images and videos based on an editing schema. ```APIDOC ## CoreEditingEngine Class ### Description This class is responsible for the actual generation of videos and images according to a provided editing schema. ### Methods #### `generate_image(self, schema:Dict[str, Any], output_file)` - Generates an image based on the editing schema and saves it to the specified output file. - **Parameters**: - `schema` (Dict[str, Any]) - The editing schema. - `output_file` (string) - The path to save the generated image. - **Returns**: - `string` - The path to the saved image. #### `generate_video(self, schema:Dict[str, Any], output_file, logger=None)` - Generates a video based on the editing schema and saves it to the specified output file. - **Parameters**: - `schema` (Dict[str, Any]) - The editing schema. - `output_file` (string) - The path to save the generated video. - `logger` (object, optional) - An optional logger object for logging the rendering progress. - **Returns**: - `string` - The path to the saved video. #### `process_common_actions(self, clip: Union[VideoFileClip, ImageClip, TextClip, AudioFileClip], actions: List[Dict[str, Any]])` - Processes common actions for the given clip. - **Parameters**: - `clip` (Union[VideoFileClip, ImageClip, TextClip, AudioFileClip]) - The clip to process. - `actions` (List[Dict[str, Any]]) - The list of actions to apply to the clip. - **Returns**: - The processed clip. ``` -------------------------------- ### RedditShortEngine: Generate Script Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/engine/README.md Generates the script for a Reddit short video using the getInterestingRedditQuestion function from the reddit_gpt module. This method overrides the base class implementation. ```python def _generateScript(self): self.script = reddit_gpt.getInterestingRedditQuestion(self.prompt, self.language) ``` -------------------------------- ### Generate Voice Recording with Eleven API Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/api_utils/README.md Generates a voice recording from text using the Eleven API and saves it to a file. Allows customization of voice character, stability, and clarity. Requires an API key for authentication. Returns the filename on success, or an empty string on failure. ```python def generateVoice(text, character, fileName, stability=0.2, clarity=0.1, api_key=""): """Generates a voice recording from text using the Eleven API. Args: text (str): The text to convert to speech. character (str): The name of the voice character to use. fileName (str): The name of the file to save the audio to. stability (float): The stability of the voice. clarity (float): The clarity of the voice. api_key (str): Your Eleven API key. Returns: str: The filename if the voice was generated successfully, otherwise an empty string. """ voices = getVoices(api_key) character_id = voices.get(character) if not character_id: return '' headers = { "Accept": "audio/mpeg", "Content-Type": "application/json", "xi-api-key": api_key } payload = { "text": text, "model_id": "eleven_monolingual_v1", "voice_settings": { "stability": stability, "similarity_boost": clarity } } response = requests.post(f"https://api.elevenlabs.io/v1/text-to-speech/{character_id}", json=payload, headers=headers) if response.status_code == 200: with open(fileName, "wb") as f: f.write(response.content) return fileName else: return '' ``` -------------------------------- ### Video Handling Utilities Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/editing_utils/README.md Functions for retrieving YouTube video/audio information and extracting video clips. ```APIDOC ## Function: getYoutubeAudio(url) ### Description Retrieves the audio URL and duration from a YouTube video. ### Parameters #### Query Parameters - **url** (string) - Required - The URL of the YouTube video. ### Response Example ```json { "example": ["http://example.com/audio.mp3", 120.5] } ``` ### Error Handling Returns `None` if the retrieval fails. ``` ```APIDOC ## Function: getYoutubeVideoLink(url) ### Description Retrieves the video URL and duration from a YouTube video. ### Parameters #### Query Parameters - **url** (string) - Required - The URL of the YouTube video. ### Response Example ```json { "example": ["http://example.com/video.mp4", 180.75] } ``` ### Error Handling Returns `None` if the retrieval fails. ``` ```APIDOC ## Function: extract_random_clip_from_video(video_url, video_duration, clip_duration, output_file) ### Description Extracts a random clip from a video and saves it to an output file. It randomly selects a start time and extracts a clip of the specified duration. ### Parameters #### Request Body - **video_url** (string) - Required - The URL of the video. - **video_duration** (float) - Required - The duration of the video in seconds. - **clip_duration** (float) - Required - The duration of the clip to extract in seconds. - **output_file** (string) - Required - The file path for the extracted clip. ### Error Handling Raises an exception if the extraction fails or the output file is not created. ``` -------------------------------- ### Path Utilities Source: https://github.com/rayventura/shortgpt/blob/stable/shortGPT/config/README.md Utility functions for searching and retrieving program paths. ```APIDOC ## search_program ### Description Searches for the specified program and returns its path. ### Method Not applicable (function) ### Endpoint Not applicable (function) ### Parameters #### Path Parameters - **program_name** (str) - Required - The name of the program to search for. ### Returns - The path of the program, or None if the program is not found. ## get_program_path ### Description Retrieves the path of the specified program. ### Method Not applicable (function) ### Endpoint Not applicable (function) ### Parameters #### Path Parameters - **program_name** (str) - Required - The name of the program. ### Returns - The path of the program, or None if the program is not found. ``` -------------------------------- ### Check ElevenLabs Language Support Source: https://context7.com/rayventura/shortgpt/llms.txt Verify if German is supported by ElevenLabs. This check is crucial before attempting to use ElevenLabs for German text-to-speech. ```python # Check ElevenLabs supported languages if Language.GERMAN in ELEVEN_SUPPORTED_LANGUAGES: print("German is supported by ElevenLabs") ```