Skip to content

Commit

Permalink
Merge pull request #946 from maiko3tattun/1125_FixAudioTranscribe
Browse files Browse the repository at this point in the history
Fix exception catching in audio transcribe
  • Loading branch information
stakira authored Nov 30, 2023
2 parents ac6afbd + 484923c commit 3bca5b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
23 changes: 10 additions & 13 deletions OpenUtau.Core/Analysis/Some.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
using NWaves.Signals;
using OpenUtau.Core.Ustx;

namespace OpenUtau.Core.Analysis.Some{
namespace OpenUtau.Core.Analysis.Some {
public static class AudioSlicer{
static int sample_rate = 44100;
static float threshold = 0.02f;
Expand Down Expand Up @@ -182,17 +180,16 @@ struct SomeResult{
}

public Some() {
try {
Location = Path.Combine(PathManager.Inst.DependencyPath, "some");
var config = Yaml.DefaultDeserializer.Deserialize<SomeConfig>(
File.ReadAllText(Path.Combine(Location, "some.yaml"),
System.Text.Encoding.UTF8));
session = Onnx.getInferenceSession(Path.Combine(Location, config.model));
}
catch (Exception ex) {
Location = Path.Combine(PathManager.Inst.DependencyPath, "some");
string yamlpath = Path.Combine(Location, "some.yaml");
if (!File.Exists(yamlpath)) {
//TODO: onnx download site
throw new Exception($"Error loading SOME. Please download SOME from https://github.com/xunmengshe/OpenUtau/releases/0.0.0.0\n{ex.Message}");
throw new FileNotFoundException($"Error loading SOME. Please download SOME from\nhttps://github.com/xunmengshe/OpenUtau/releases/0.0.0.0");
}

var config = Yaml.DefaultDeserializer.Deserialize<SomeConfig>(
File.ReadAllText(yamlpath, System.Text.Encoding.UTF8));
session = Onnx.getInferenceSession(Path.Combine(Location, config.model));
}

SomeResult Analyze(float[] samples) {
Expand Down
9 changes: 7 additions & 2 deletions OpenUtau/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,9 +1101,14 @@ void Transcribe(UPart part){
});
}
});
transcribeTask.ContinueWith(task =>{
var voicePart = task.Result;
transcribeTask.ContinueWith(task => {
msgbox?.Close();
if (task.IsFaulted) {
Log.Error(task.Exception, $"Failed to transcribe part {part.name}");
MessageBox.ShowError(this, task.Exception);
return;
}
var voicePart = task.Result;
//Add voicePart into project
if(voicePart != null){
var project = DocManager.Inst.Project;
Expand Down

0 comments on commit 3bca5b9

Please sign in to comment.