hu-po commited on
Commit
b038b32
1 Parent(s): 68a8488

release 0.1

Browse files
Files changed (2) hide show
  1. src/src/elevenlabs.py +14 -2
  2. src/src/openailib.py +6 -1
src/src/elevenlabs.py CHANGED
@@ -5,7 +5,7 @@ import os
5
  import time
6
  from concurrent.futures import ThreadPoolExecutor
7
  from dataclasses import dataclass
8
- from typing import Dict, List, Union, Tuple
9
 
10
  import sounddevice as sd
11
  import soundfile as sf
@@ -16,7 +16,11 @@ from .utils import timeit
16
  logging.basicConfig(level=logging.INFO)
17
  log = logging.getLogger(__name__)
18
 
19
- USER = ElevenLabsUser(os.environ["ELEVENLABS_API_KEY"])
 
 
 
 
20
 
21
 
22
  @dataclass
@@ -71,6 +75,10 @@ async def save_history(history: List[Tuple[Speaker, str]], audio_savepath: str):
71
 
72
 
73
  def check_voice_exists(voice: Union[ElevenLabsVoice, str]) -> Union[ElevenLabsVoice, None]:
 
 
 
 
74
  log.info(f"Getting voice {voice}...")
75
  _available_voices = USER.get_voices_by_name(voice)
76
  if _available_voices:
@@ -81,6 +89,10 @@ def check_voice_exists(voice: Union[ElevenLabsVoice, str]) -> Union[ElevenLabsVo
81
 
82
  @timeit
83
  def get_make_voice(voice: Union[ElevenLabsVoice, str], audio_path: List[str] = None) -> ElevenLabsVoice:
 
 
 
 
84
  _voice = check_voice_exists(voice)
85
  if _voice is not None:
86
  return _voice
 
5
  import time
6
  from concurrent.futures import ThreadPoolExecutor
7
  from dataclasses import dataclass
8
+ from typing import List, Union, Tuple
9
 
10
  import sounddevice as sd
11
  import soundfile as sf
 
16
  logging.basicConfig(level=logging.INFO)
17
  log = logging.getLogger(__name__)
18
 
19
+ try:
20
+ USER = ElevenLabsUser(os.environ["ELEVENLABS_API_KEY"])
21
+ except KeyError as e:
22
+ log.warning("ELEVENLABS_API_KEY not found in environment variables.")
23
+ pass
24
 
25
 
26
  @dataclass
 
75
 
76
 
77
  def check_voice_exists(voice: Union[ElevenLabsVoice, str]) -> Union[ElevenLabsVoice, None]:
78
+ if USER is None:
79
+ log.warning(
80
+ "No ElevenLabsUser found, have you set the ELEVENLABS_API_KEY environment variable?")
81
+ return None
82
  log.info(f"Getting voice {voice}...")
83
  _available_voices = USER.get_voices_by_name(voice)
84
  if _available_voices:
 
89
 
90
  @timeit
91
  def get_make_voice(voice: Union[ElevenLabsVoice, str], audio_path: List[str] = None) -> ElevenLabsVoice:
92
+ if USER is None:
93
+ log.warning(
94
+ "No ElevenLabsUser found, have you set the ELEVENLABS_API_KEY environment variable?")
95
+ return None
96
  _voice = check_voice_exists(voice)
97
  if _voice is not None:
98
  return _voice
src/src/openailib.py CHANGED
@@ -4,11 +4,16 @@ import os
4
  from .utils import timeit
5
 
6
  import openai
7
- openai.api_key = os.getenv("OPENAI_API_KEY")
8
 
9
  logging.basicConfig(level=logging.INFO)
10
  log = logging.getLogger(__name__)
11
 
 
 
 
 
 
 
12
 
13
  @timeit
14
  def speech_to_text(audio_path):
 
4
  from .utils import timeit
5
 
6
  import openai
 
7
 
8
  logging.basicConfig(level=logging.INFO)
9
  log = logging.getLogger(__name__)
10
 
11
+ try:
12
+ openai.api_key = os.getenv("OPENAI_API_KEY")
13
+ except KeyError as e:
14
+ log.warning("OPENAI_API_KEY not found in environment variables.")
15
+ pass
16
+
17
 
18
  @timeit
19
  def speech_to_text(audio_path):