GithubHelp home page GithubHelp logo

rajtilakjee / keepyourmouthshut Goto Github PK

View Code? Open in Web Editor NEW
66.0 4.0 2.0 24.92 MB

Acid Reflux for your Ears!

License: GNU General Public License v3.0

Python 77.44% HTML 22.56%
elevenlabs openai openai-api opensource podcast edge-tts llmos

keepyourmouthshut's People

Contributors

rajtilakjee avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

keepyourmouthshut's Issues

UnboundLocalError: cannot access local variable 'audio_segment' where it is not associated with a value

I have a function that used ElevenLabs API which worked fine. However, it incurred a lot of cost even during prototyping. So I thought it would be best to go for Edge-TTS. I am getting an error message:

UnboundLocalError: cannot access local variable 'audio_segment' where it is not associated with a value

Here's the ElevenLabs API code:

from elevenlabs import generate, set_api_key, Voice, VoiceSettings
from pydub import AudioSegment
import io
import os
import hashlib
from utils.os_stuff import get_env_var_or_fail
import logging

set_api_key(get_env_var_or_fail('ELEVEN_LABS_API_KEY'))

HOST_VOICE = Voice(
    voice_id="21m00Tcm4TlvDq8ikWAM",
    name="Rachel",
    category="premade",
    settings=VoiceSettings(stability=0.35, similarity_boost=0.9),
)

ADS_VOICE = Voice(
    voice_id="TxGEqnHWrfWFTfGW9XjX",
    name="Josh",
    category="premade",
    settings=VoiceSettings(stability=0.35, similarity_boost=0.9),
)


def load_audio_bytes(audio_bytes):
    audio_file = io.BytesIO(audio_bytes)
    audio_segment = AudioSegment.from_file(audio_file, format='mp3')
    return audio_segment


def convert_text_to_mp3(text, voice):
    # Generate the cache key by MD5 hashing the text
    cache_key = hashlib.md5(text.encode()).hexdigest()

    # Check if the file already exists in cache
    cache_dir = ".eleven_labs_cache"
    cache_file = os.path.join(cache_dir, f"{cache_key}.mp3")

    if not os.path.exists(cache_dir):
        os.makedirs(cache_dir)

    if os.path.exists(cache_file):
        # If it does exist, load and return as an AudioSegment
        audio_segment = AudioSegment.from_mp3(cache_file)
    else:
        # If it does not exist, call the API, create, save, and return as an AudioSegment
        char_count = len(text)
        logging.info(f'Calling eleven labs for {char_count} chars...')
        section_1_voice_over = load_audio_bytes(generate(
            text=text,
            voice=voice
        ))
        section_1_voice_over.export(cache_file, format='mp3')
        audio_segment = section_1_voice_over

    return audio_segment

And here's the Edge-TTS code:

import asyncio
import edge_tts
from pydub import AudioSegment

VOICE = "en-GB-SoniaNeural"

def convert_text_to_mp3(text):
    loop = asyncio.get_event_loop_policy().get_event_loop()
    try:
        audio_segment = loop.run_until_complete(edge_tts.Communicate(text, VOICE))
    finally:
        loop.close()
        return audio_segment

Application crashes - KeyError: 'choices'

Describe the bug

Crash on clicking "Generate"

(keepyourmouthshut) alan@ziggy:~/Source/rajtilakjee/keepyourmouthshut$ python app/keepyourmouthshut.py                                                                                        
 * Serving Flask app 'keepyourmouthshut'                                                                                                                                                      
 * Debug mode: on                                                                              
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.                                                                                                                        
 * Running on all addresses (0.0.0.0)                                                                                                                                                                                                                                           
 * Running on http://127.0.0.1:64215                                                                                   
 * Running on http://10.0.25.12:64215                                                                                                                                                                                                         
Press CTRL+C to quit                                                                                                                                                                                                                                                            
 * Restarting with stat                                                                                                
 * Debugger is active!                                                                                                                  
 * Debugger PIN: 103-517-491                                                                                                                                                                                                                  
127.0.0.1 - - [26/Mar/2024 18:45:20] "GET / HTTP/1.1" 200 -                                                                                                                                                                                   
127.0.0.1 - - [26/Mar/2024 18:45:20] "GET /static/kyms-logo.png HTTP/1.1" 200 -                                                                                                                                                               
127.0.0.1 - - [26/Mar/2024 18:45:21] "GET /static/kyms-logo.png HTTP/1.1" 304 -                                                                                                                                                                                                 
127.0.0.1 - - [26/Mar/2024 18:46:17] "POST /generate HTTP/1.1" 500 -                                                                    
Traceback (most recent call last):                                                                                                      
  File "/home/alan/Source/rajtilakjee/keepyourmouthshut/lib/python3.11/site-packages/flask/app.py", line 1478, in __call__                                                                                                                                                      
    return self.wsgi_app(environ, start_response)                                                                                                                                                                                                                               
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                               
  File "/home/alan/Source/rajtilakjee/keepyourmouthshut/lib/python3.11/site-packages/flask/app.py", line 1458, in wsgi_app                                                                                                                                                      
    response = self.handle_exception(e)                             
               ^^^^^^^^^^^^^^^^^^^^^^^^                             
  File "/home/alan/Source/rajtilakjee/keepyourmouthshut/lib/python3.11/site-packages/flask/app.py", line 1455, in wsgi_app                                                                                                                                                      
    response = self.full_dispatch_request()                         
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                         
  File "/home/alan/Source/rajtilakjee/keepyourmouthshut/lib/python3.11/site-packages/flask/app.py", line 869, in full_dispatch_request                                                                                                                                          
    rv = self.handle_user_exception(e)                              
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                              
  File "/home/alan/Source/rajtilakjee/keepyourmouthshut/lib/python3.11/site-packages/flask/app.py", line 867, in full_dispatch_request                                                                                                                                          
    rv = self.dispatch_request()                                    
         ^^^^^^^^^^^^^^^^^^^^^^^                                    
  File "/home/alan/Source/rajtilakjee/keepyourmouthshut/lib/python3.11/site-packages/flask/app.py", line 852, in dispatch_request                                                                                                                                               
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)                                                            
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                            
  File "/home/alan/Source/rajtilakjee/keepyourmouthshut/app/keepyourmouthshut.py", line 49, in generate                                                                                                                                                                         
    mp3_file, txt_file = generate_podcast(name, desc, topics, adverts)                                                                  
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                  
  File "/home/alan/Source/rajtilakjee/keepyourmouthshut/app/generate_podcast.py", line 50, in generate_podcast                                                                                                                                                                  
    script_segment = llmOS_stuff.generate_response(                                                                                     
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                     
  File "/home/alan/Source/rajtilakjee/keepyourmouthshut/app/utils/llmOS_stuff.py", line 49, in generate_response                                                                                                                                                                
    result = answer["choices"][0]["message"]["content"]                                                                                 
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                 
KeyError: 'choices'                                                 

To Reproduce
Steps to reproduce the behavior:

  • Launched in a venv
  • visited the page
  • filled in the fields
  • and hit "generate". It crashed.

Crash pasted above

Expected behavior

A viral podcast episode to be generated! :D

Screenshots

image

Desktop (please complete the following information):

  • OS: Ubuntu 23.10
  • Browser Microsoft Edge
  • Version Version 122.0.2365.92 (Official build) (64-bit)

Additional context

I cloned the repo, and did the pip install of requirements (which is incorrect in the readme, by the way, as requirements is in the app folder, not the root).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.