fomext commited on
Commit
e1b863f
·
verified ·
1 Parent(s): 5915333

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +26 -20
main.py CHANGED
@@ -178,10 +178,6 @@ async def transcribe(
178
  description="Highest frequency to transcribe in Hz (e.g. 2000 for voice). "
179
  "Leave empty for no upper limit.",
180
  ),
181
- include_pitch_bends: bool = Form(
182
- True,
183
- description="Whether to detect and return sub-semitone pitch bend data.",
184
- ),
185
  multiple_pitch_bends: bool = Form(
186
  False,
187
  description="Allow multiple simultaneous pitch bends (polyphonic pitch bend). "
@@ -231,24 +227,34 @@ async def transcribe(
231
  tmp.write(audio_bytes)
232
  tmp_path = tmp.name
233
 
234
- try:
235
- # ── Validate & clamp user settings ───────────────────────────────────
236
- onset_threshold = _clamp(onset_threshold, 0.05, 0.95)
237
- frame_threshold = _clamp(frame_threshold, 0.05, 0.95)
238
- min_note_length = max(0.01, min_note_length)
239
 
 
240
  # ── Run basic-pitch ───────────────────────────────────────────────────
 
 
 
 
 
 
 
 
 
 
241
  _model_output, midi_data, note_events = predict(
242
  tmp_path,
243
- _MODEL, # pre-loaded — no cold start per request
244
- onset_threshold=onset_threshold,
245
- frame_threshold=frame_threshold,
246
- minimum_note_length=min_note_length,
247
- minimum_frequency=min_frequency,
248
- maximum_frequency=max_frequency,
249
- include_pitch_bends=include_pitch_bends,
250
- multiple_pitch_bends=multiple_pitch_bends,
251
- melodia_trick=melodia_trick,
252
  )
253
 
254
  except Exception as exc:
@@ -277,10 +283,10 @@ async def transcribe(
277
  settings={
278
  "onset_threshold": onset_threshold,
279
  "frame_threshold": frame_threshold,
280
- "min_note_length": min_note_length,
 
281
  "min_frequency": min_frequency,
282
  "max_frequency": max_frequency,
283
- "include_pitch_bends": include_pitch_bends,
284
  "multiple_pitch_bends": multiple_pitch_bends,
285
  "melodia_trick": melodia_trick,
286
  },
 
178
  description="Highest frequency to transcribe in Hz (e.g. 2000 for voice). "
179
  "Leave empty for no upper limit.",
180
  ),
 
 
 
 
181
  multiple_pitch_bends: bool = Form(
182
  False,
183
  description="Allow multiple simultaneous pitch bends (polyphonic pitch bend). "
 
227
  tmp.write(audio_bytes)
228
  tmp_path = tmp.name
229
 
230
+ # ── Validate & clamp user settings (before try so always defined) ────────
231
+ onset_threshold = _clamp(onset_threshold, 0.05, 0.95)
232
+ frame_threshold = _clamp(frame_threshold, 0.05, 0.95)
233
+ min_note_length = max(0.01, min_note_length)
234
+ min_note_length_ms = min_note_length * 1000.0 # basic-pitch wants ms, not s
235
 
236
+ try:
237
  # ── Run basic-pitch ───────────────────────────────────────────────────
238
+ # Exact signature (basic-pitch >= 0.3.x):
239
+ # predict(audio_path, model_or_model_path,
240
+ # onset_threshold, frame_threshold,
241
+ # minimum_note_length, ← in MILLISECONDS, not seconds
242
+ # minimum_frequency, maximum_frequency,
243
+ # multiple_pitch_bends, melodia_trick,
244
+ # debug_file, midi_tempo)
245
+ # NOTE: `include_pitch_bends` was removed from predict(); pitch bends
246
+ # are now always detected internally and stored in the MIDI output.
247
+
248
  _model_output, midi_data, note_events = predict(
249
  tmp_path,
250
+ _MODEL, # pre-loaded — no cold start per request
251
+ onset_threshold,
252
+ frame_threshold,
253
+ min_note_length_ms,
254
+ min_frequency, # None = no lower bound
255
+ max_frequency, # None = no upper bound
256
+ multiple_pitch_bends,
257
+ melodia_trick,
 
258
  )
259
 
260
  except Exception as exc:
 
283
  settings={
284
  "onset_threshold": onset_threshold,
285
  "frame_threshold": frame_threshold,
286
+ "min_note_length_seconds": min_note_length,
287
+ "min_note_length_ms": min_note_length_ms,
288
  "min_frequency": min_frequency,
289
  "max_frequency": max_frequency,
 
290
  "multiple_pitch_bends": multiple_pitch_bends,
291
  "melodia_trick": melodia_trick,
292
  },