update main
This commit is contained in:
1 parent
ee6069e5d5
commit
da59f3d6e3
6 files changed
+3272
-1341
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -1,42 +0,0 @@
|
||||
from openai import OpenAI
|
||||
from difflib import SequenceMatcher
|
||||
from dataclasses import dataclass
|
||||
from typing import List, Tuple
|
||||
import aiohttp, json
|
||||
|
||||
|
||||
@dataclass
|
||||
class TimestampedLyric:
|
||||
text: str
|
||||
start: float
|
||||
end: float
|
||||
|
||||
SUNO_BASE_URL="https://api.sunoapi.org"
|
||||
SUNO_TIMESTAMP_ROUTE = "/api/v1/generate/get-timestamped-lyrics"
|
||||
SUNO_DETAIL_ROUTE = "/api/v1/generate/record-info"
|
||||
|
||||
class LyricTimestampMapper:
|
||||
suno_api_key : str
|
||||
def __init__(self, suno_api_key):
|
||||
self.suno_api_key = suno_api_key
|
||||
|
||||
async def get_suno_audio_id_from_task_id(self, suno_task_id): # expire if db save audio id
|
||||
url = f"{SUNO_BASE_URL}{SUNO_DETAIL_ROUTE}"
|
||||
headers = {"Authorization": f"Bearer {self.suno_api_key}"}
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url, headers=headers, params={"taskId" : suno_task_id}) as response:
|
||||
detail = await response.json()
|
||||
result = detail['data']['response']['sunoData'][0]['id']
|
||||
return result
|
||||
|
||||
async def get_suno_timestamp(self, suno_task_id, suno_audio_id): # expire if db save audio id
|
||||
url = f"{SUNO_BASE_URL}{SUNO_TIMESTAMP_ROUTE}"
|
||||
headers = {"Authorization": f"Bearer {self.suno_api_key}"}
|
||||
payload = {
|
||||
"task_id" : suno_task_id,
|
||||
"audio_id" : suno_audio_id
|
||||
}
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(url, headers=headers, data=json.dumps(payload)) as response:
|
||||
result = await response.json()
|
||||
return result
|
||||
@@ -1,19 +0,0 @@
|
||||
from lyric_timestamp_mapper import LyricTimestampMapper
|
||||
|
||||
API_KEY = "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"
|
||||
AUDIO_PATH = "test_audio.mp3"
|
||||
|
||||
GROUND_TRUTH_LYRICS = [
|
||||
"첫 번째 가사 라인입니다",
|
||||
"두 번째 가사 라인입니다",
|
||||
"세 번째 가사 라인입니다",
|
||||
]
|
||||
|
||||
mapper = LyricTimestampMapper(api_key=API_KEY)
|
||||
result = mapper.map_ground_truth(AUDIO_PATH, GROUND_TRUTH_LYRICS)
|
||||
|
||||
for lyric in result:
|
||||
if lyric.start >= 0:
|
||||
print(f"[{lyric.start:.2f} - {lyric.end:.2f}] {lyric.text}")
|
||||
else:
|
||||
print(f"[매칭 실패] {lyric.text}")
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user