Skip to content

Commit

Permalink
add triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
andantei committed Mar 10, 2023
1 parent f398e9c commit 510ade8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 29 deletions.
4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from plugin import AudioLDMPlugin
from tuneflow_devkit import Runner
from pathlib import Path
import uvicorn

app = Runner(plugin_class_list=[AudioLDMPlugin], bundle_file_path=str(
Path(__file__).parent.joinpath('bundle.json').absolute())).start(path_prefix='/plugins/audio-ldm')

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
60 changes: 34 additions & 26 deletions bundle.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
{
"plugins": [
{
"providerId": "andantei",
"providerDisplayName": {
"zh": "Andantei行板",
"en": "Andantei"
},
"pluginId": "audioldm-generate",
"pluginDisplayName": {
"zh": "[AI] 文字生成音频 (AudioLDM)",
"en": "[AI] Text-to-Audio (AudioLDM)"
},
"pluginDescription": {
"zh": "用一段提示词生成音频或音乐",
"en": "Generate audio or music from a short prompt text"
},
"version": "1.0.0",
"supportedPlatforms": ["desktop"],
"isInDevelopment": true,
"minRequiredDesktopVersion": "1.8.9",
"options": {
"allowReset": true,
"allowManualApplyAdjust": true
"plugins": [
{
"providerId": "andantei",
"providerDisplayName": {
"zh": "Andantei行板",
"en": "Andantei"
},
"pluginId": "audioldm-generate",
"pluginDisplayName": {
"zh": "[AI] 文字生成音频 (AudioLDM)",
"en": "[AI] Text-to-Audio (AudioLDM)"
},
"pluginDescription": {
"zh": "用一段提示词生成音频或音乐",
"en": "Generate audio or music from a short prompt text"
},
"version": "1.0.0",
"supportedPlatforms": ["desktop"],
"minRequiredDesktopVersion": "1.8.9",
"options": {
"allowReset": true,
"allowManualApplyAdjust": true
},
"triggers": [
{
"type": "context-track-content",
"config": {
"allowedTrackTypes": ["audio"]
}
}
}
]
}
],
"categories": ["generate"]
}
]
}
9 changes: 7 additions & 2 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tuneflow_py import TuneflowPlugin, ParamDescriptor, Song, TrackType, WidgetType, InjectSource
from tuneflow_py import TuneflowPlugin, ParamDescriptor, Song, WidgetType, InjectSource, TuneflowPluginTriggerData
from typing import Dict, Any
from audioldm import text_to_audio, build_model
from pathlib import Path
Expand Down Expand Up @@ -110,6 +110,11 @@ def params(song: Song) -> Dict[str, ParamDescriptor]:

@staticmethod
def run(song: Song, params: Dict[str, Any]):
trigger: TuneflowPluginTriggerData = params["trigger"]
track_id =trigger["entities"][0]["trackId"]
track = song.get_track_by_id(track_id=track_id)
if track is None:
raise Exception('track not found')
model_path = str(Path(__file__).parent.joinpath('ckpt/ldm_trimmed.ckpt').absolute())
model = build_model(ckpt_path=model_path)
# TODO: Support prompt i18n
Expand All @@ -123,7 +128,6 @@ def run(song: Song, params: Dict[str, Any]):
for file_bytes in file_bytes_list:
try:
file_bytes.seek(0)
track = song.create_track(type=TrackType.AUDIO_TRACK)
track.create_audio_clip(clip_start_tick=0, audio_clip_data={
"audio_data": {
"format": "wav",
Expand All @@ -132,6 +136,7 @@ def run(song: Song, params: Dict[str, Any]):
"duration": params["duration"],
"start_tick": params["playhead_tick"]
})
break
except:
print(traceback.format_exc())

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ pandas
torchlibrosa==0.0.9
transformers
ftfy
tuneflow-py>=0.3.0
tuneflow-py>=0.3.6

0 comments on commit 510ade8

Please sign in to comment.