OpenVoice
OpenVoice copied to clipboard
OPENAI_API_KEY ?
run the demo_part2.ipynb. /lib/python3.10/site-packages/openai/_client.py", line 100, in init raise OpenAIError( openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
how to slove it,tks
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
I must use the client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY")) ,can i chang it to othes?
I'm having the same issue, I have loaded my .env key into the /home/user/anaconda3/envs/openvoice/lib/python3.9/site-packages/openai directory, /home/user/Documents/GitHub/OpenVoice/ and the /home/user/Documents/OpenVoiceTest (this where my python script is to convert the text) directory. But I keep getting the same error as described above:
python3 SentenceChangeOVClone.py
/home/user/anaconda3/envs/openvoice/lib/python3.9/site-packages/torch/nn/utils/weight_norm.py:28: UserWarning: torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm.
warnings.warn("torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm.")
Loaded checkpoint '/home/user/Documents/GitHub/OpenVoice/checkpoints/converter/checkpoint.pth'
missing/unexpected keys: [] []
Traceback (most recent call last):
File "/home/user/Documents/OpenVoiceTest/SentenceChangeOVClone.py", line 23, in <module>
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
File "/home/user/anaconda3/envs/openvoice/lib/python3.9/site-packages/openai/_client.py", line 98, in __init__
raise OpenAIError(
openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
This is my code:
import os
import torch
from openvoice import se_extractor
from openvoice.api import ToneColorConverter
ckpt_converter = '/home/user/Documents/GitHub/OpenVoice/checkpoints/converter'
device="cuda:0" if torch.cuda.is_available() else "cpu"
output_dir = '/home/user/Documents/Victor/ovout'
tone_color_converter = ToneColorConverter(f'{ckpt_converter}/config.json', device=device)
tone_color_converter.load_ckpt(f'{ckpt_converter}/checkpoint.pth')
os.makedirs(output_dir, exist_ok=True)
from openai import OpenAI
from dotenv import load_dotenv
# Please create a file named .env and place your
# OpenAI key as OPENAI_API_KEY=xxx
load_dotenv()
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
response = client.audio.speech.create(
model="tts-1",
voice="nova",
input="This audio will be used to extract the base speaker tone color embedding. " + \
"Typically a very short audio should be sufficient, but increasing the audio " + \
"length will also improve the output audio quality."
)
response.stream_to_file(f"{output_dir}/openai_source_output.mp3")
base_speaker = f"{output_dir}/openai_source_output.mp3"
source_se, audio_name = se_extractor.get_se(base_speaker, tone_color_converter, vad=True)
reference_speaker = '/home/user/Documents/OpenVoice/SampleVoice.mp3'
target_se, audio_name = se_extractor.get_se(reference_speaker, tone_color_converter, vad=True)
# Run the base speaker tts
text = [
"MyShell is a decentralized and comprehensive platform for discovering, creating, and staking AI-native apps.",
"MyShell es una plataforma descentralizada y completa para descubrir, crear y apostar por aplicaciones nativas de IA.",
"MyShell est une plateforme décentralisée et complète pour découvrir, créer et miser sur des applications natives d'IA.",
"MyShell ist eine dezentralisierte und umfassende Plattform zum Entdecken, Erstellen und Staken von KI-nativen Apps.",
"MyShell è una piattaforma decentralizzata e completa per scoprire, creare e scommettere su app native di intelligenza artificiale.",
"MyShellは、AIネイティブアプリの発見、作成、およびステーキングのための分散型かつ包括的なプラットフォームです。",
"MyShell — это децентрализованная и всеобъемлющая платформа для обнаружения, создания и стейкинга AI-ориентированных приложений.",
"MyShell هي منصة لامركزية وشاملة لاكتشاف وإنشاء ورهان تطبيقات الذكاء الاصطناعي الأصلية.",
"MyShell是一个去中心化且全面的平台,用于发现、创建和投资AI原生应用程序。",
"MyShell एक विकेंद्रीकृत और व्यापक मंच है, जो AI-मूल ऐप्स की खोज, सृजन और स्टेकिंग के लिए है।",
"MyShell é uma plataforma descentralizada e abrangente para descobrir, criar e apostar em aplicativos nativos de IA."
]
src_path = f'{output_dir}/tmp.wav'
for i, t in enumerate(text):
response = client.audio.speech.create(
model="tts-1",
voice="nova",
input=t,
)
response.stream_to_file(src_path)
save_path = f'{output_dir}/output_crosslingual_{i}.wav'
# Run the tone color converter
encode_message = "@MyShell"
tone_color_converter.convert(
audio_src_path=src_path,
src_se=source_se,
tgt_se=target_se,
output_path=save_path,
message=encode_message)
Does anyone know where I am going wrong?
OK, I have figured it out, I think. I have found the relevent alternative to this using Ubuntu via XDA Developers.
I have so far run export OPENAI_API_KEY="sk-the rest of my key"
Looking at the guide, it looks like this has to be set each time, but there is a permanent way of setting it using /etc/environment.
This is the guide I found
https://www.xda-developers.com/set-environment-variable-in-ubuntu/