├── .clang-format ├── .github └── workflows │ └── windows-rel-build.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── scripts ├── cmake │ ├── WinResource.rc.in │ ├── utils.cmake │ └── winrc.cmake ├── setup-onnxruntime.cmake ├── vcpkg-manifest │ └── vcpkg.json └── vcpkg │ ├── ports │ └── ffmpeg-fake │ │ ├── portfile.cmake │ │ └── vcpkg.json │ └── triplets │ ├── arm64-osx.cmake │ ├── x64-linux.cmake │ ├── x64-osx.cmake │ └── x64-windows.cmake └── src ├── CMakeLists.txt ├── apps ├── AudioSlicer │ ├── CMakeLists.txt │ ├── main.cpp │ ├── slicer │ │ ├── enumerations.h │ │ ├── mainwindow.cpp │ │ ├── mainwindow.h │ │ ├── mainwindow_ui.cpp │ │ ├── mainwindow_ui.h │ │ ├── mathutils.h │ │ ├── slicer.cpp │ │ ├── slicer.h │ │ ├── workthread.cpp │ │ └── workthread.h │ └── utils │ │ ├── winfont.cpp │ │ └── winfont.h ├── CMakeLists.txt ├── FoxBreatheLabeler │ ├── CMakeLists.txt │ ├── gui │ │ ├── MainWindow.cpp │ │ └── MainWindow.h │ ├── main.cpp │ ├── res │ │ ├── qss.qrc │ │ └── qss │ │ │ ├── flatgray.css │ │ │ └── flatgray │ │ │ ├── add_bottom.png │ │ │ ├── add_left.png │ │ │ ├── add_right.png │ │ │ ├── add_top.png │ │ │ ├── arrow_bottom.png │ │ │ ├── arrow_left.png │ │ │ ├── arrow_right.png │ │ │ ├── arrow_top.png │ │ │ ├── branch_close.png │ │ │ ├── branch_open.png │ │ │ ├── calendar_nextmonth.png │ │ │ ├── calendar_prevmonth.png │ │ │ ├── checkbox_checked.png │ │ │ ├── checkbox_checked_disable.png │ │ │ ├── checkbox_parcial.png │ │ │ ├── checkbox_parcial_disable.png │ │ │ ├── checkbox_unchecked.png │ │ │ ├── checkbox_unchecked_disable.png │ │ │ ├── menu_checked.png │ │ │ ├── radiobutton_checked.png │ │ │ ├── radiobutton_checked_disable.png │ │ │ ├── radiobutton_unchecked.png │ │ │ └── radiobutton_unchecked_disable.png │ └── util │ │ ├── Fbl.cpp │ │ ├── Fbl.h │ │ ├── FblModel.cpp │ │ ├── FblModel.h │ │ ├── FblThread.cpp │ │ ├── FblThread.h │ │ └── textgrid.hpp ├── LyricFA │ ├── CMakeLists.txt │ ├── gui │ │ ├── MainWindow.cpp │ │ └── MainWindow.h │ ├── main.cpp │ ├── res │ │ ├── qss.qrc │ │ └── qss │ │ │ ├── flatgray.css │ │ │ └── flatgray │ │ │ ├── add_bottom.png │ │ │ ├── add_left.png │ │ │ ├── add_right.png │ │ │ ├── add_top.png │ │ │ ├── arrow_bottom.png │ │ │ ├── arrow_left.png │ │ │ ├── arrow_right.png │ │ │ ├── arrow_top.png │ │ │ ├── branch_close.png │ │ │ ├── branch_open.png │ │ │ ├── calendar_nextmonth.png │ │ │ ├── calendar_prevmonth.png │ │ │ ├── checkbox_checked.png │ │ │ ├── checkbox_checked_disable.png │ │ │ ├── checkbox_parcial.png │ │ │ ├── checkbox_parcial_disable.png │ │ │ ├── checkbox_unchecked.png │ │ │ ├── checkbox_unchecked_disable.png │ │ │ ├── menu_checked.png │ │ │ ├── radiobutton_checked.png │ │ │ ├── radiobutton_checked_disable.png │ │ │ ├── radiobutton_unchecked.png │ │ │ └── radiobutton_unchecked_disable.png │ └── util │ │ ├── Asr.cpp │ │ ├── Asr.h │ │ ├── AsrThread.cpp │ │ ├── AsrThread.h │ │ ├── FaTread.cpp │ │ ├── FaTread.h │ │ ├── LevenshteinDistance.cpp │ │ ├── LevenshteinDistance.h │ │ ├── MatchLyric.cpp │ │ ├── MatchLyric.h │ │ └── MathUtils.h ├── MinLabel │ ├── CMakeLists.txt │ ├── gui │ │ ├── Common.cpp │ │ ├── Common.h │ │ ├── ExportDialog.cpp │ │ ├── ExportDialog.h │ │ ├── MainWindow.cpp │ │ ├── MainWindow.h │ │ ├── PlayWidget.cpp │ │ ├── PlayWidget.h │ │ ├── TextWidget.cpp │ │ └── TextWidget.h │ ├── main.cpp │ ├── res.qrc │ └── res │ │ ├── app.qss │ │ ├── audio.svg │ │ ├── clipboard.svg │ │ ├── pause.svg │ │ ├── play.svg │ │ ├── qss.qrc │ │ ├── qss │ │ ├── flatgray.css │ │ └── flatgray │ │ │ ├── add_bottom.png │ │ │ ├── add_left.png │ │ │ ├── add_right.png │ │ │ ├── add_top.png │ │ │ ├── arrow_bottom.png │ │ │ ├── arrow_left.png │ │ │ ├── arrow_right.png │ │ │ ├── arrow_top.png │ │ │ ├── branch_close.png │ │ │ ├── branch_open.png │ │ │ ├── calendar_nextmonth.png │ │ │ ├── calendar_prevmonth.png │ │ │ ├── checkbox_checked.png │ │ │ ├── checkbox_checked_disable.png │ │ │ ├── checkbox_parcial.png │ │ │ ├── checkbox_parcial_disable.png │ │ │ ├── checkbox_unchecked.png │ │ │ ├── checkbox_unchecked_disable.png │ │ │ ├── menu_checked.png │ │ │ ├── radiobutton_checked.png │ │ │ ├── radiobutton_checked_disable.png │ │ │ ├── radiobutton_unchecked.png │ │ │ └── radiobutton_unchecked_disable.png │ │ └── stop.svg ├── SlurCutter │ ├── CMakeLists.txt │ ├── gui │ │ ├── DsSentence.h │ │ ├── F0Widget.cpp │ │ ├── F0Widget.h │ │ ├── MainWindow.cpp │ │ ├── MainWindow.h │ │ ├── PlayWidget.cpp │ │ ├── PlayWidget.h │ │ └── intervaltree.hpp │ ├── main.cpp │ ├── res.qrc │ └── res │ │ ├── app.qss │ │ ├── audio.svg │ │ ├── clipboard.svg │ │ ├── pause.svg │ │ ├── play.svg │ │ └── stop.svg └── SomeInfer │ ├── CMakeLists.txt │ ├── gui │ ├── BatchWidget.cpp │ ├── BatchWidget.h │ ├── MainWindow.cpp │ ├── MainWindow.h │ ├── MidiWidget.cpp │ └── MidiWidget.h │ ├── main.cpp │ └── utils │ ├── DmlGpuUtils.cpp │ ├── DmlGpuUtils.h │ └── GpuInfo.h ├── libs ├── CMakeLists.txt ├── FunAsr │ ├── Acknowledge.md │ ├── CMakeLists.txt │ ├── LICENSE │ ├── MODEL_LICENSE │ ├── README.md │ ├── README_zh.md │ ├── include │ │ ├── Audio.h │ │ ├── ComDefine.h │ │ └── Model.h │ └── src │ │ ├── Audio.cpp │ │ ├── CMakeLists.txt │ │ ├── FeatureExtract.cpp │ │ ├── FeatureExtract.h │ │ ├── FeatureQueue.cpp │ │ ├── FeatureQueue.h │ │ ├── Model.cpp │ │ ├── SpeechWrap.cpp │ │ ├── SpeechWrap.h │ │ ├── Tensor.h │ │ ├── Vocab.cpp │ │ ├── Vocab.h │ │ ├── alignedmem.cpp │ │ ├── alignedmem.h │ │ ├── commonfunc.h │ │ ├── paraformer_onnx.cpp │ │ ├── paraformer_onnx.h │ │ ├── predefine_coe.h │ │ ├── tmp.h │ │ ├── util.cpp │ │ └── util.h ├── audio-util │ ├── .clang-format │ ├── .gitignore │ ├── CMakeLists.txt │ ├── LICENSE │ ├── audio-utilConfig.cmake.in │ ├── cmake │ │ └── winrc.cmake │ ├── include │ │ └── audio-util │ │ │ ├── AudioUtilGlobal.h │ │ │ ├── Slicer.h │ │ │ ├── SndfileVio.h │ │ │ └── Util.h │ ├── src │ │ ├── FlacDecoder.cpp │ │ ├── FlacDecoder.h │ │ ├── MathUtils.h │ │ ├── Mp3Decoder.cpp │ │ ├── Mp3Decoder.h │ │ ├── Slicer.cpp │ │ ├── SndfileVio.cpp │ │ └── Util.cpp │ └── tests │ │ ├── CMakeLists.txt │ │ └── main.cpp ├── ffmpegdecoder │ ├── CMakeLists.txt │ ├── FFmpegDecoder.cpp │ ├── FFmpegDecoder.h │ └── private │ │ ├── FFmpegDecoder_p.cpp │ │ └── FFmpegDecoder_p.h ├── qsmedia │ ├── Api │ │ ├── IAudioDecoder.cpp │ │ ├── IAudioDecoder.h │ │ ├── IAudioEncoder.cpp │ │ ├── IAudioEncoder.h │ │ ├── IAudioPlayback.cpp │ │ ├── IAudioPlayback.h │ │ ├── factories │ │ │ ├── AudioDecoderFactory.cpp │ │ │ ├── AudioDecoderFactory.h │ │ │ ├── AudioEncoderFactory.cpp │ │ │ ├── AudioEncoderFactory.h │ │ │ ├── AudioPlaybackFactory.cpp │ │ │ └── AudioPlaybackFactory.h │ │ ├── interfaces │ │ │ ├── IAudioDecoderPlugin.cpp │ │ │ ├── IAudioDecoderPlugin.h │ │ │ ├── IAudioEncoderPlugin.cpp │ │ │ ├── IAudioEncoderPlugin.h │ │ │ ├── IAudioPlaybackPlugin.cpp │ │ │ └── IAudioPlaybackPlugin.h │ │ └── private │ │ │ └── IAudioPlayback_p.h │ ├── CMakeLists.txt │ ├── NAudio │ │ ├── NAudioGlobal.h │ │ ├── WaveFormat.cpp │ │ ├── WaveFormat.h │ │ ├── WaveFormatEncoding.cpp │ │ ├── WaveFormatEncoding.h │ │ ├── WaveFormatExtraData.cpp │ │ ├── WaveFormatExtraData.h │ │ ├── WaveStream.cpp │ │ └── WaveStream.h │ ├── QsMediaGlobal.h │ └── QsMediaNamespace.h ├── rmvpe-infer │ ├── .clang-format │ ├── .gitignore │ ├── CMakeLists.txt │ ├── LICENSE │ ├── cmake │ │ └── winrc.cmake │ ├── include │ │ └── rmvpe-infer │ │ │ ├── Provider.h │ │ │ ├── Rmvpe.h │ │ │ ├── RmvpeGlobal.h │ │ │ └── RmvpeModel.h │ ├── rmvpe-inferConfig.cmake.in │ ├── src │ │ ├── Rmvpe.cpp │ │ └── RmvpeModel.cpp │ └── tests │ │ ├── CMakeLists.txt │ │ └── main.cpp ├── sdlplayback │ ├── CMakeLists.txt │ ├── SDLPlayback.cpp │ ├── SDLPlayback.h │ ├── plugin.json │ └── private │ │ ├── SDLPlayback_p.cpp │ │ └── SDLPlayback_p.h └── some-infer │ ├── .clang-format │ ├── .gitignore │ ├── CMakeLists.txt │ ├── LICENSE │ ├── cmake │ └── winrc.cmake │ ├── include │ └── some-infer │ │ ├── Provider.h │ │ ├── Some.h │ │ ├── SomeGlobal.h │ │ └── SomeModel.h │ ├── some-inferConfig.cmake.in │ ├── src │ ├── Some.cpp │ └── SomeModel.cpp │ └── tests │ ├── CMakeLists.txt │ └── main.cpp └── tests └── CMakeLists.txt /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | 3 | # 指针和引用的对齐方式。 4 | # 可能的值有: 5 | # PAS_Left (在配置中: Left) 指针左对齐。 6 | # PAS_Right (在配置中: Right) 指针右对齐。 7 | # PAS_Middle (在配置中: Middle) 指针中间对齐。 8 | PointerAlignment: Right 9 | 10 | # public/protected/private 等访问修饰符偏移量 11 | AccessModifierOffset: -4 12 | 13 | # 缩进长度 14 | IndentWidth: 4 15 | 16 | # 连续空行的最大数 17 | MaxEmptyLinesToKeep: 999 18 | 19 | # 在OC中的@property后面添加一个空格。例如:使用“@property (readonly)”而不是“@property(readonly)” 20 | ObjCSpaceAfterProperty: true 21 | 22 | # OC块中所拍的字符数 23 | ObjCBlockIndentWidth: 4 24 | 25 | # 取决于值, 语句“int f() { return 0; }”可以被放到一个单行。 26 | # 可能的值有: 27 | # SFS_None (在配置中: None) 从不合并方法或函数到单独的一行。 28 | # SFS_Empty (在配置中: Empty) 仅合并空的函数。 29 | # SFS_Inline (在配置中: Inline) 仅合并类中定义的方法或函数. 意味着 “empty”. 30 | # SFS_All (在配置中: All) 合并所有的方法适应单行. 31 | AllowShortFunctionsOnASingleLine: None 32 | 33 | # 如果为真(true), 语句“if (a) return;” 能被放到单行。 34 | AllowShortIfStatementsOnASingleLine: false 35 | 36 | # 如果为真(true), 对齐注释。 37 | AlignTrailingComments: true 38 | 39 | # 如果为真,对齐连续的宏定义 40 | AlignConsecutiveMacros: true 41 | 42 | # 如果为真(true),将会在“[”之后和“]”之前插入空格。 43 | SpacesInSquareBrackets: false 44 | 45 | # 如果为真(true), 将会在“(”之后和“)”之前插入空格。 46 | SpacesInParentheses : false 47 | 48 | # 如果为真(true), 校准连续的声明。 49 | # 这将会校准连续多行的声明的名字。这将会导致像下面这样的格式: 50 | # int aaaa = 12; 51 | # float b = 23; 52 | # std::string ccc = 23; 53 | AlignConsecutiveDeclarations: false 54 | 55 | # 如果为真(true),连续调整多行 56 | # 这将会调整连续行中的分配操作符。这将会导致像下面这样的格式: 57 | # int aaaa = 12; 58 | # int b = 23; 59 | # int ccc = 23; 60 | AlignConsecutiveAssignments: false 61 | 62 | # 如果为假(false),移除分配操作符(=)前空格。 63 | SpaceBeforeAssignmentOperators: true 64 | 65 | # 如果为真(true), 将会在字面量容器中插入空格(例如 OC和Javascript的数组和字典字面量)。 66 | SpacesInContainerLiterals: false 67 | 68 | # 缩进case标签 69 | IndentCaseLabels: true 70 | 71 | # 如果表达式中包含函数调用,并且函数调用因为表达式太长被放到了下一行,是否缩进 72 | IndentWrappedFunctionNames: true 73 | 74 | # 如果为真(true), 保持块的起始空行。 75 | # true: false: 76 | # if (foo) { vs. if (foo) { 77 | # bar(); 78 | # bar(); } 79 | # } 80 | KeepEmptyLinesAtTheStartOfBlocks: true 81 | 82 | # 允许所有参数都被放在下一行 83 | AllowAllParametersOfDeclarationOnNextLine: false 84 | 85 | # 使用C风格强制类型转换后,是否在中间添加一个空格 86 | SpaceAfterCStyleCast: true 87 | 88 | # 在模板定义后换行 89 | AlwaysBreakTemplateDeclarations: Yes 90 | 91 | # Tab长度 92 | TabWidth: 4 93 | 94 | # 是否使用Tab 95 | UseTab: Never 96 | 97 | # 在括号后对齐参数 98 | # someLongFunction(argument1, 99 | # argument2); 100 | AlignAfterOpenBracket: Align 101 | 102 | # 名字空间内部缩进 103 | NamespaceIndentation: All 104 | 105 | # 一行最长列数 106 | ColumnLimit: 120 107 | 108 | # 按层次缩进宏定义 109 | IndentPPDirectives: AfterHash 110 | 111 | # 数组元素对齐 112 | AlignArrayOfStructures: Left 113 | 114 | # ContinuationIndentWidth: 0 115 | 116 | FixNamespaceComments: false 117 | 118 | StatementMacros: ['__qas_attr__', '__qas_exclude__', '__qas_include__'] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.log 6 | *.autosave 7 | *.a 8 | *.core 9 | *.moc 10 | *.o 11 | *.obj 12 | *.orig 13 | *.rej 14 | *.so 15 | *.so.* 16 | *_pch.h.cpp 17 | *_resource.rc 18 | *.qm 19 | .#* 20 | *.*# 21 | core 22 | !core/ 23 | tags 24 | .DS_Store 25 | .directory 26 | *.debug 27 | Makefile* 28 | *.prl 29 | *.app 30 | moc_*.cpp 31 | ui_*.h 32 | qrc_*.cpp 33 | Thumbs.db 34 | # *.res 35 | # *.rc 36 | /.qmake.cache 37 | /.qmake.stash 38 | 39 | # qtcreator generated files 40 | *.pro.user* 41 | 42 | # xemacs temporary files 43 | *.flc 44 | 45 | # Vim temporary files 46 | .*.swp 47 | 48 | # Visual Studio generated files 49 | *.ib_pdb_index 50 | *.idb 51 | *.ilk 52 | *.pdb 53 | *.sln 54 | *.suo 55 | *.vcproj 56 | *vcproj.*.*.user 57 | *.ncb 58 | *.sdf 59 | *.opensdf 60 | *.vcxproj 61 | *vcxproj.* 62 | 63 | # MinGW generated files 64 | *.Debug 65 | *.Release 66 | 67 | # Python byte code 68 | __pycache__ 69 | *.pyc 70 | 71 | # Binaries 72 | # -------- 73 | *.dll 74 | *.exe 75 | 76 | .DS_Store 77 | */.DS_Store 78 | 79 | build-src* 80 | build/ 81 | cmake-build* 82 | *.user 83 | *.lnk 84 | Libs/* 85 | _workingDir* 86 | .vscode 87 | .idea 88 | .cache 89 | cache 90 | .vs 91 | out/ 92 | CMakeSettings.json 93 | /vcpkg 94 | /data 95 | /*.natvis 96 | 97 | *.sublime-* 98 | setup-vcpkg.json 99 | setup-vcpkg-temp* 100 | /src/libs/onnxruntime/ 101 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.17) 2 | 3 | project(dataset-tools) 4 | 5 | if (WIN32) 6 | set(ONNXRUNTIME_ENABLE_DML ON) 7 | endif () 8 | 9 | set(CMAKE_CXX_STANDARD 17) 10 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 11 | 12 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 13 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 14 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 15 | 16 | if (MSVC) 17 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /manifest:no") 18 | set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /manifest:no") 19 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /manifest:no") 20 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") 21 | endif () 22 | 23 | set(PROJECT_CMAKE_MODULES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake) 24 | 25 | add_subdirectory(src) 26 | -------------------------------------------------------------------------------- /scripts/cmake/WinResource.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef VS_VERSION_INFO 4 | #define VS_VERSION_INFO 1 5 | #endif 6 | 7 | #define _STRINGIFY(x) #x 8 | #define STRINGIFY(x) _STRINGIFY(x) 9 | 10 | @RC_ICON_COMMENT@ IDI_ICON1 ICON DISCARDABLE STRINGIFY(@RC_ICON_PATH@) 11 | 12 | VS_VERSION_INFO VERSIONINFO 13 | FILEVERSION @RC_VERSION@ 14 | PRODUCTVERSION @RC_VERSION@ 15 | { 16 | BLOCK "StringFileInfo" 17 | { 18 | // U.S. English - Windows, Multilingual 19 | BLOCK "040904E4" 20 | { 21 | VALUE "FileDescription", STRINGIFY(@RC_DESCRIPTION@) 22 | VALUE "FileVersion", STRINGIFY(@RC_VERSION_STRING@) 23 | VALUE "ProductName", STRINGIFY(@RC_APPLICATION_NAME@) 24 | VALUE "ProductVersion", STRINGIFY(@RC_VERSION_STRING@) 25 | VALUE "LegalCopyright", STRINGIFY(@RC_COPYRIGHT@) 26 | } 27 | } 28 | BLOCK "VarFileInfo" 29 | { 30 | VALUE "Translation", 0x409, 1252 // 1252 = 0x04E4 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /scripts/cmake/utils.cmake: -------------------------------------------------------------------------------- 1 | # Copied from ChorusKit 2 | function(parse_version _prefix _version) 3 | string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)" _ ${_version}) 4 | 5 | foreach(_i RANGE 1 4) 6 | if(${CMAKE_MATCH_COUNT} GREATER_EQUAL ${_i}) 7 | set(_tmp ${CMAKE_MATCH_${_i}}) 8 | else() 9 | set(_tmp 0) 10 | endif() 11 | 12 | set(${_prefix}_${_i} ${_tmp} PARENT_SCOPE) 13 | endforeach() 14 | endfunction() -------------------------------------------------------------------------------- /scripts/cmake/winrc.cmake: -------------------------------------------------------------------------------- 1 | include(${CMAKE_CURRENT_LIST_DIR}/utils.cmake) 2 | 3 | parse_version(_version ${PROJECT_VERSION}) 4 | 5 | # No Icon 6 | set(RC_ICON_COMMENT "//") 7 | set(RC_ICON_PATH) 8 | 9 | # Metadata 10 | set(RC_VERSION ${_version_1},${_version_2},${_version_3},${_version_4}) 11 | set(RC_APPLICATION_NAME ${PROJECT_NAME}) 12 | set(RC_VERSION_STRING ${PROJECT_VERSION}) 13 | 14 | if(NOT DEFINED RC_DESCRIPTION) 15 | set(RC_DESCRIPTION ${PROJECT_NAME}) 16 | endif() 17 | 18 | if(NOT DEFINED RC_COPYRIGHT) 19 | set(RC_COPYRIGHT "Copyright 2022-2023 OpenVPI") 20 | endif() 21 | 22 | # Generate rc file 23 | set(_rc_path ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_res.rc) 24 | configure_file(${CMAKE_CURRENT_LIST_DIR}/WinResource.rc.in ${_rc_path} @ONLY) 25 | 26 | # Add source 27 | target_sources(${PROJECT_NAME} PRIVATE ${_rc_path}) 28 | -------------------------------------------------------------------------------- /scripts/vcpkg-manifest/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", 3 | "dependencies": [ 4 | "sdl2", 5 | "ffmpeg-fake", 6 | "fftw3", 7 | "yaml-cpp", 8 | "cpp-pinyin", 9 | "cpp-kana", 10 | "soxr", 11 | "wolf-midi", 12 | "libsndfile" 13 | ], 14 | "vcpkg-configuration": { 15 | "overlay-ports": [ 16 | "../vcpkg/ports" 17 | ], 18 | "overlay-triplets": [ 19 | "../vcpkg/triplets" 20 | ] 21 | } 22 | } -------------------------------------------------------------------------------- /scripts/vcpkg/ports/ffmpeg-fake/portfile.cmake: -------------------------------------------------------------------------------- 1 | set(LIB_PREFIX "https://github.com/SineStriker/ffmpeg-fake/releases/download") 2 | set(LIB_VERSION 0.0.5) 3 | 4 | if(WIN32) 5 | set(FILE_NAME ffmpeg-fake-windows-amd64-${LIB_VERSION}.zip) 6 | set(FILE_CHECK_SUM 05c3582cf9dba7478b498570ab6d2c7a776d53e51542263cc37a270c6b2f6a08e8a8b52d5d439a2d2d89274cc2d57224c5bc93a5e1beebf6ab41aeb399469d9c) 7 | elseif(APPLE) 8 | if(VCPKG_OSX_ARCHITECTURES STREQUAL arm64) 9 | set(FILE_NAME ffmpeg-fake-mac-arm64-${LIB_VERSION}.zip) 10 | set(FILE_CHECK_SUM 37b53104aa0c685c4e946080bb228ef6cf534c7ed2aebd3b472bca0c2e4989c83eb650c4a9f75aeaa111f1aebd6d8514964f6824577f15f8576e3931de874808) 11 | else() 12 | set(FILE_NAME ffmpeg-fake-mac-amd64-${LIB_VERSION}.zip) 13 | set(FILE_CHECK_SUM ac58101c9b5e94056c59ba8d114b1197872bc3cf602519cf2931bbfd860ff8a8d488733089e6e25e45508fc77f43ede8440d087a5e43603bb20716c880c47bdb) 14 | endif() 15 | else() 16 | set(FILE_NAME ffmpeg-fake-linux-amd64-${LIB_VERSION}.zip) 17 | set(FILE_CHECK_SUM ac79eb418d101ddd17f48a3ed1b4b47dbb990ed723920a09d9eadcaf2c8a26010ad4d57b4fa1ec15ffdce470d18ddf9941cb18faa920c78fea52cbf1c99beaac) 18 | endif() 19 | 20 | vcpkg_download_distfile(ARCHIVE 21 | URLS ${LIB_PREFIX}/${LIB_VERSION}/${FILE_NAME} 22 | FILENAME ${FILE_NAME} 23 | SHA512 ${FILE_CHECK_SUM} 24 | ) 25 | 26 | vcpkg_extract_source_archive( 27 | SOURCE_PATH 28 | ARCHIVE "${ARCHIVE}" 29 | 30 | # NO_REMOVE_ONE_LEVEL 31 | ) 32 | 33 | vcpkg_cmake_configure( 34 | SOURCE_PATH "${SOURCE_PATH}" 35 | OPTIONS 36 | -DCMAKE_INSTALL_INCLUDEDIR=${CURRENT_PACKAGES_DIR}/include 37 | ) 38 | 39 | vcpkg_cmake_install() 40 | vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/ffmpeg-fake) 41 | vcpkg_copy_pdbs() 42 | 43 | file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") 44 | file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") 45 | file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}/" RENAME copyright) 46 | -------------------------------------------------------------------------------- /scripts/vcpkg/ports/ffmpeg-fake/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ffmpeg-fake", 3 | "version": "0.0.5", 4 | "port-version": 1, 5 | "description": [ 6 | "a library to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created.", 7 | "FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations." 8 | ], 9 | "homepage": "https://ffmpeg.org", 10 | "license": null, 11 | "dependencies": [ 12 | { 13 | "name": "vcpkg-cmake", 14 | "host": true 15 | }, 16 | { 17 | "name": "vcpkg-cmake-config", 18 | "host": true 19 | }, 20 | "mp3lame" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /scripts/vcpkg/triplets/arm64-osx.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE arm64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE dynamic) 4 | 5 | set(VCPKG_CMAKE_SYSTEM_NAME Darwin) 6 | set(VCPKG_OSX_ARCHITECTURES arm64) -------------------------------------------------------------------------------- /scripts/vcpkg/triplets/x64-linux.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE dynamic) 4 | 5 | set(VCPKG_CMAKE_SYSTEM_NAME Linux) -------------------------------------------------------------------------------- /scripts/vcpkg/triplets/x64-osx.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE dynamic) 4 | 5 | set(VCPKG_CMAKE_SYSTEM_NAME Darwin) 6 | set(VCPKG_OSX_ARCHITECTURES x86_64) -------------------------------------------------------------------------------- /scripts/vcpkg/triplets/x64-windows.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE dynamic) -------------------------------------------------------------------------------- /src/apps/AudioSlicer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(AudioSlicer VERSION 0.0.1.4) 2 | 3 | set(CMAKE_AUTOMOC ON) 4 | set(CMAKE_AUTORCC ON) 5 | set(CMAKE_AUTOUIC ON) 6 | 7 | file(GLOB_RECURSE _src *.h *.cpp) 8 | add_executable(${PROJECT_NAME} ${_src}) 9 | 10 | find_package(SndFile CONFIG REQUIRED) 11 | target_link_libraries(${PROJECT_NAME} PRIVATE 12 | SndFile::sndfile 13 | Qt${QT_VERSION_MAJOR}::Core 14 | Qt${QT_VERSION_MAJOR}::Widgets 15 | ) 16 | 17 | target_compile_definitions(${PROJECT_NAME} PRIVATE 18 | APP_VERSION="${PROJECT_VERSION}" 19 | ) 20 | 21 | target_include_directories(${PROJECT_NAME} PRIVATE .) 22 | 23 | if(WIN32) 24 | include(${PROJECT_CMAKE_MODULES_DIR}/winrc.cmake) 25 | 26 | if(NOT ${CMAKE_BUILD_TYPE} MATCHES "Deb") 27 | set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE) 28 | endif() 29 | endif() 30 | 31 | if(APPLE) 32 | set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE) 33 | endif() 34 | 35 | set_property(TARGET DeployedTargets APPEND PROPERTY TARGETS ${PROJECT_NAME}) -------------------------------------------------------------------------------- /src/apps/AudioSlicer/main.cpp: -------------------------------------------------------------------------------- 1 | #include "slicer/mainwindow.h" 2 | 3 | #include 4 | 5 | 6 | #ifdef Q_OS_WIN 7 | #include "utils/winfont.h" 8 | #endif 9 | 10 | 11 | int main(int argc, char *argv[]) { 12 | //QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 13 | //QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); 14 | QApplication a(argc, argv); 15 | a.setApplicationName("Audio Slicer"); 16 | a.setApplicationDisplayName("Audio Slicer"); 17 | 18 | #ifdef Q_OS_WIN 19 | // If the operating system is Windows, set app font face and size to system settings. 20 | setWinFont(); 21 | #endif 22 | 23 | // Set library loading info 24 | // #ifdef Q_OS_MAC 25 | // qApp->addLibraryPath(qApp->applicationDirPath() + "/../Frameworks/ChorusKit/plugins"); 26 | // #else 27 | // qApp->addLibraryPath(qApp->applicationDirPath() + "/../lib/ChorusKit/plugins"); 28 | // #endif 29 | 30 | MainWindow w; 31 | w.show(); 32 | 33 | return a.exec(); 34 | } 35 | -------------------------------------------------------------------------------- /src/apps/AudioSlicer/slicer/enumerations.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_SLICER_CONSTANTS_H 2 | #define AUDIO_SLICER_CONSTANTS_H 3 | 4 | #include 5 | 6 | enum WaveFormat { 7 | WF_INT16_PCM, 8 | WF_INT24_PCM, 9 | WF_INT32_PCM, 10 | WF_FLOAT32 11 | }; 12 | Q_DECLARE_METATYPE(WaveFormat) 13 | 14 | enum class SlicingMode { 15 | AudioOnly, 16 | AudioOnlyLoadMarkers, 17 | MarkersOnly, 18 | AudioAndMarkers 19 | }; 20 | Q_DECLARE_METATYPE(SlicingMode) 21 | 22 | #endif // AUDIO_SLICER_CONSTANTS_H -------------------------------------------------------------------------------- /src/apps/AudioSlicer/slicer/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_SLICER_MAINWINDOW_H 2 | #define AUDIO_SLICER_MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef Q_OS_WIN 15 | #include 16 | #endif 17 | 18 | 19 | QT_BEGIN_NAMESPACE 20 | namespace Ui { class MainWindow; } 21 | QT_END_NAMESPACE 22 | 23 | class MainWindow : public QMainWindow { 24 | Q_OBJECT 25 | 26 | public: 27 | explicit MainWindow(QWidget *parent = nullptr); 28 | 29 | ~MainWindow() override; 30 | 31 | protected: 32 | // events 33 | void closeEvent(QCloseEvent *event) override; 34 | void dragEnterEvent(QDragEnterEvent *event) override; 35 | void dropEvent(QDropEvent *event) override; 36 | void showEvent(QShowEvent *event) override; 37 | 38 | #ifdef Q_OS_WIN 39 | protected: 40 | bool nativeEvent(const QByteArray &eventType, void *message, 41 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 42 | qintptr 43 | #else 44 | long 45 | #endif 46 | *result) override; 47 | #endif 48 | 49 | public slots: 50 | void slot_browseOutputDir(); 51 | void slot_addAudioFiles(); 52 | void slot_addFolder(); 53 | void slot_removeListItem(); 54 | void slot_clearAudioList(); 55 | void slot_slicingModeChanged(int index); 56 | void slot_about(); 57 | void slot_aboutQt(); 58 | void slot_start(); 59 | void slot_saveLogs(); 60 | void slot_oneFinished(const QString &filename, int listIndex); 61 | void slot_oneInfo(const QString &infomsg); 62 | void slot_oneError(const QString &errmsg); 63 | void slot_oneFailed(const QString &errmsg, int listIndex); 64 | void slot_threadFinished(); 65 | void slot_updateFilenameExample(int value); 66 | 67 | private: 68 | Ui::MainWindow *ui; 69 | 70 | bool m_processing; 71 | bool m_windowLoaded; 72 | int m_workTotal; 73 | int m_workFinished; 74 | int m_workError; 75 | QStringList m_failIndex; 76 | QThreadPool *m_threadpool; 77 | 78 | void warningProcessNotFinished(); 79 | void setProcessing(bool processing); 80 | void logMessage(const QString &txt); 81 | void addSingleAudioFile(const QString &fullPath); 82 | void initStylesMenu(); 83 | 84 | #ifdef Q_OS_WIN 85 | private: 86 | ITaskbarList3* m_pTaskbarList3; 87 | HWND m_hwnd; 88 | #endif 89 | }; 90 | 91 | 92 | #endif //AUDIO_SLICER_MAINWINDOW_H 93 | -------------------------------------------------------------------------------- /src/apps/AudioSlicer/slicer/mathutils.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_SLICER_MATHUTILS_H 2 | #define AUDIO_SLICER_MATHUTILS_H 3 | 4 | 5 | template 6 | inline T divIntRound(T n, T d); 7 | 8 | template 9 | inline T divIntRound(T n, T d) { 10 | /* 11 | * Integer division rounding to the closest integer, without converting to floating point numbers. 12 | */ 13 | // T should be an integer type (int, int64_t, qint64, ...) 14 | return ((n < 0) ^ (d < 0)) ? \ 15 | ((n - (d / 2)) / d) : \ 16 | ((n + (d / 2)) / d); 17 | } 18 | 19 | #endif // AUDIO_SLICER_MATHUTILS_H 20 | -------------------------------------------------------------------------------- /src/apps/AudioSlicer/slicer/slicer.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_SLICER_SLICER_H 2 | #define AUDIO_SLICER_SLICER_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | using MarkerList = std::vector>; 10 | 11 | class SndfileHandle; 12 | 13 | enum SlicerErrorCode { 14 | SLICER_OK = 0, 15 | SLICER_INVALID_ARGUMENT, 16 | SLICER_AUDIO_ERROR 17 | }; 18 | 19 | class Slicer { 20 | private: 21 | double m_threshold; 22 | qint64 m_hopSize; 23 | qint64 m_winSize; 24 | qint64 m_minLength; 25 | qint64 m_minInterval; 26 | qint64 m_maxSilKept; 27 | SlicerErrorCode m_errCode; 28 | QString m_errMsg; 29 | SndfileHandle *m_decoder; 30 | 31 | public: 32 | explicit Slicer(SndfileHandle *decoder, double threshold = -40.0, qint64 minLength = 5000, qint64 minInterval = 300, qint64 hopSize = 20, qint64 maxSilKept = 5000); 33 | MarkerList slice(); 34 | SlicerErrorCode getErrorCode(); 35 | QString getErrorMsg(); 36 | }; 37 | 38 | #endif //AUDIO_SLICER_SLICER_H -------------------------------------------------------------------------------- /src/apps/AudioSlicer/slicer/workthread.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_SLICER_WORKTHREAD_H 2 | #define AUDIO_SLICER_WORKTHREAD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "enumerations.h" 11 | 12 | class WorkThread : public QObject, public QRunnable { 13 | Q_OBJECT 14 | public: 15 | WorkThread(const QString &filename, 16 | const QString &outPath, 17 | double threshold, 18 | qint64 minLength, 19 | qint64 minInterval, 20 | qint64 hopSize, 21 | qint64 maxSilKept, 22 | int outputWaveFormat = WF_INT16_PCM, 23 | bool saveAudio = true, 24 | bool saveMarkers = false, 25 | bool loadMarkers = false, 26 | bool overwriteMarkers = false, 27 | int minimumDigits = 3, 28 | int listIndex = -1); 29 | void run() override; 30 | 31 | private: 32 | QString m_filename; 33 | QString m_outPath; 34 | double m_threshold; 35 | qint64 m_minLength; 36 | qint64 m_minInterval; 37 | qint64 m_hopSize; 38 | qint64 m_maxSilKept; 39 | int m_outputWaveFormat; 40 | bool m_saveAudio; 41 | bool m_saveMarkers; 42 | bool m_loadMarkers; 43 | bool m_overwriteMarkers; 44 | int m_minimumDigits; 45 | int m_listIndex; 46 | 47 | signals: 48 | void oneFinished(const QString &filename, int listIndex); 49 | void oneInfo(const QString &infomsg); 50 | void oneError(const QString &errmsg); 51 | void oneFailed(const QString &filename, int listIndex); 52 | }; 53 | 54 | 55 | #endif //AUDIO_SLICER_WORKTHREAD_H 56 | -------------------------------------------------------------------------------- /src/apps/AudioSlicer/utils/winfont.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifdef Q_OS_WIN 5 | #include 6 | #endif 7 | 8 | void setWinFont() { 9 | #ifdef Q_OS_WIN 10 | // For Windows only. 11 | // Use Win32 API to retrieve the non-client metrics, including the system text font. 12 | // If success, set application font to system text font. 13 | NONCLIENTMETRICSW metrics = {sizeof(NONCLIENTMETRICSW)}; 14 | if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &metrics, 0)) { 15 | // Get font properties, and construct a `QFont` object 16 | // Font face 17 | QString fontFace = QString::fromWCharArray(metrics.lfMessageFont.lfFaceName); 18 | 19 | // Font point size 20 | qreal fontPointSize = 0.0; 21 | HDC hDC = GetDC(nullptr); 22 | if (hDC) { 23 | // To get font point size, we first get font height (in logical units) and device DPI, 24 | // then calculate the point size. 25 | // Here, we use message text font. 26 | // Reference: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-logfontw 27 | int dpiY = GetDeviceCaps(hDC, LOGPIXELSY); 28 | fontPointSize = -72.0 * metrics.lfMessageFont.lfHeight / dpiY; 29 | ReleaseDC(nullptr, hDC); 30 | } 31 | 32 | QFont font(fontFace); 33 | if (fontPointSize > 0) { 34 | font.setPointSizeF(fontPointSize); 35 | } 36 | qApp->setFont(font); 37 | } 38 | #endif 39 | } -------------------------------------------------------------------------------- /src/apps/AudioSlicer/utils/winfont.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_SLICER_WINFONT_H 2 | #define AUDIO_SLICER_WINFONT_H 3 | 4 | void setWinFont(); 5 | 6 | #endif // AUDIO_SLICER_WINFONT_H 7 | -------------------------------------------------------------------------------- /src/apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(MinLabel) 2 | add_subdirectory(SlurCutter) 3 | add_subdirectory(AudioSlicer) 4 | add_subdirectory(LyricFA) 5 | add_subdirectory(FoxBreatheLabeler) 6 | add_subdirectory(SomeInfer) -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(FoxBreatheLabeler VERSION 0.0.0.1) 2 | 3 | set(CMAKE_AUTOMOC ON) 4 | set(CMAKE_AUTORCC ON) 5 | set(CMAKE_AUTOUIC ON) 6 | 7 | file(GLOB_RECURSE _src *.h *.hpp *.cpp) 8 | add_executable(${PROJECT_NAME} ${_src} res/qss.qrc) 9 | 10 | find_package(SndFile CONFIG REQUIRED) 11 | find_package(yaml-cpp CONFIG REQUIRED) 12 | 13 | include_directories(../../libs/onnxruntime/include) 14 | target_include_directories(${PROJECT_NAME} PUBLIC ../../libs/onnxruntime/include) 15 | target_link_directories(${PROJECT_NAME} PUBLIC ../../libs/onnxruntime/lib) 16 | 17 | target_link_libraries(${PROJECT_NAME} PRIVATE 18 | SndFile::sndfile 19 | Qt${QT_VERSION_MAJOR}::Core 20 | Qt${QT_VERSION_MAJOR}::Widgets 21 | audio-util yaml-cpp::yaml-cpp 22 | onnxruntime 23 | ) 24 | 25 | file(GLOB_RECURSE onnx_files ../../libs/onnxruntime/lib/*.*) 26 | foreach (onnx_file ${onnx_files}) 27 | file(COPY ${onnx_file} DESTINATION ${CMAKE_BINARY_DIR}/bin) 28 | endforeach () 29 | 30 | target_compile_definitions(${PROJECT_NAME} PRIVATE 31 | APP_VERSION="${PROJECT_VERSION}" 32 | ) 33 | 34 | target_include_directories(${PROJECT_NAME} PRIVATE .) 35 | 36 | if (WIN32) 37 | include(${PROJECT_CMAKE_MODULES_DIR}/winrc.cmake) 38 | 39 | if (NOT ${CMAKE_BUILD_TYPE} MATCHES "Deb") 40 | set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE) 41 | endif () 42 | endif () 43 | 44 | set(DIRECTORIES_TO_COPY 45 | dict 46 | ) 47 | 48 | if (APPLE) 49 | set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE) 50 | 51 | foreach (dir ${DIRECTORIES_TO_COPY}) 52 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 53 | COMMAND 54 | ${CMAKE_COMMAND} -E copy_directory 55 | ${CMAKE_BINARY_DIR}/bin/${dir} 56 | $/Resources/${dir} 57 | ) 58 | endforeach () 59 | endif () 60 | 61 | set_property(TARGET DeployedTargets APPEND PROPERTY TARGETS ${PROJECT_NAME}) -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/gui/MainWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "../util/Fbl.h" 18 | 19 | #include 20 | 21 | namespace FBL { 22 | class MainWindow final : public QMainWindow { 23 | Q_OBJECT 24 | public: 25 | explicit MainWindow(QWidget *parent = nullptr); 26 | ~MainWindow() override; 27 | 28 | protected: 29 | QMenu *fileMenu; 30 | QAction *addFileAction; 31 | QAction *addFolderAction; 32 | 33 | QMenu *helpMenu; 34 | QAction *aboutAppAction; 35 | QAction *aboutQtAction; 36 | 37 | QWidget *mainWidget; 38 | QListWidget *taskList; 39 | QVBoxLayout *mainLayout; 40 | QHBoxLayout *listLayout; 41 | QHBoxLayout *btnLayout; 42 | 43 | QPushButton *remove; 44 | QPushButton *clear; 45 | QPushButton *runFbl; 46 | 47 | QPlainTextEdit *out; 48 | QProgressBar *progressBar; 49 | 50 | QVBoxLayout *rightLayout; 51 | QHBoxLayout *rawTgLayout; 52 | QHBoxLayout *outTgLayout; 53 | 54 | QHBoxLayout *apThreshLayout; 55 | QHBoxLayout *apDurLayout; 56 | QHBoxLayout *spDurLayout; 57 | 58 | QLineEdit *rawTgEdit; 59 | QLineEdit *outTgEdit; 60 | 61 | QDoubleSpinBox *ap_threshold; 62 | QDoubleSpinBox *ap_dur; 63 | QDoubleSpinBox *sp_dur; 64 | 65 | QCheckBox *pinyinBox; 66 | 67 | QLabel *progressLabel; 68 | QHBoxLayout *progressLayout; 69 | 70 | void addFiles(const QStringList &paths) const; 71 | void addFolder(const QString &path) const; 72 | 73 | void dragEnterEvent(QDragEnterEvent *event) override; 74 | void dropEvent(QDropEvent *event) override; 75 | void closeEvent(QCloseEvent *event) override; 76 | 77 | private: 78 | FBL *m_fbl = nullptr; 79 | 80 | int m_workTotal = 0; 81 | int m_workFinished = 0; 82 | int m_workError = 0; 83 | QStringList m_failIndex; 84 | QThreadPool *m_threadpool; 85 | 86 | static void initStyleSheet(); 87 | 88 | void slot_rawTgPath(); 89 | void slot_outTgPath(); 90 | void slot_lyricPath(); 91 | 92 | void slot_removeListItem() const; 93 | void slot_clearTaskList() const; 94 | void slot_runFbl(); 95 | 96 | void slot_oneFailed(const QString &filename, const QString &msg); 97 | void slot_oneFinished(const QString &filename, const QString &msg); 98 | void slot_threadFinished(); 99 | 100 | void _q_fileMenuTriggered(const QAction *action); 101 | void _q_helpMenuTriggered(const QAction *action); 102 | }; 103 | } 104 | #endif // MAINWINDOW_H 105 | -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/main.cpp: -------------------------------------------------------------------------------- 1 | #include "gui/MainWindow.h" 2 | #include 3 | 4 | #ifdef Q_OS_WIN 5 | #include 6 | #endif 7 | 8 | using namespace FBL; 9 | int main(int argc, char *argv[]) { 10 | QApplication a(argc, argv); 11 | 12 | #ifdef Q_OS_WIN 13 | // For Windows only. 14 | // Use Win32 API to retrieve the non-client metrics, including the system text font. 15 | // If success, set application font to system text font. 16 | NONCLIENTMETRICSW metrics = {sizeof(NONCLIENTMETRICSW)}; 17 | if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &metrics, 0)) { 18 | // Get font properties, and construct a `QFont` object 19 | // Font face 20 | QString fontFace = QString::fromWCharArray(metrics.lfMessageFont.lfFaceName); 21 | 22 | // Font point size 23 | qreal fontPointSize = 0.0; 24 | HDC hDC = GetDC(nullptr); 25 | if (hDC) { 26 | // To get font point size, we first get font height (in logical units) and device DPI, 27 | // then calculate the point size. 28 | // Here, we use message text font. 29 | // Reference: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-logfontw 30 | int dpiY = GetDeviceCaps(hDC, LOGPIXELSY); 31 | fontPointSize = -72.0 * metrics.lfMessageFont.lfHeight / dpiY; 32 | ReleaseDC(nullptr, hDC); 33 | } 34 | 35 | QFont font(fontFace); 36 | if (fontPointSize > 0) { 37 | font.setPointSizeF(fontPointSize); 38 | } 39 | qApp->setFont(font); 40 | } 41 | #endif 42 | 43 | MainWindow w; 44 | w.show(); 45 | return QApplication::exec(); 46 | } 47 | -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qss/flatgray.css 4 | qss/flatgray/add_bottom.png 5 | qss/flatgray/add_left.png 6 | qss/flatgray/add_right.png 7 | qss/flatgray/add_top.png 8 | qss/flatgray/arrow_bottom.png 9 | qss/flatgray/arrow_left.png 10 | qss/flatgray/arrow_right.png 11 | qss/flatgray/arrow_top.png 12 | qss/flatgray/branch_close.png 13 | qss/flatgray/branch_open.png 14 | qss/flatgray/calendar_nextmonth.png 15 | qss/flatgray/calendar_prevmonth.png 16 | qss/flatgray/checkbox_checked.png 17 | qss/flatgray/checkbox_checked_disable.png 18 | qss/flatgray/checkbox_parcial.png 19 | qss/flatgray/checkbox_parcial_disable.png 20 | qss/flatgray/checkbox_unchecked.png 21 | qss/flatgray/checkbox_unchecked_disable.png 22 | qss/flatgray/menu_checked.png 23 | qss/flatgray/radiobutton_checked.png 24 | qss/flatgray/radiobutton_checked_disable.png 25 | qss/flatgray/radiobutton_unchecked.png 26 | qss/flatgray/radiobutton_unchecked_disable.png 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/add_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/add_bottom.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/add_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/add_left.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/add_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/add_right.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/add_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/add_top.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/arrow_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/arrow_bottom.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/arrow_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/arrow_left.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/arrow_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/arrow_right.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/arrow_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/arrow_top.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/branch_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/branch_close.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/branch_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/branch_open.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/calendar_nextmonth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/calendar_nextmonth.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/calendar_prevmonth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/calendar_prevmonth.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_checked.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_checked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_checked_disable.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_parcial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_parcial.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_parcial_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_parcial_disable.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_unchecked.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_unchecked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/checkbox_unchecked_disable.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/menu_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/menu_checked.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/radiobutton_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/radiobutton_checked.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/radiobutton_checked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/radiobutton_checked_disable.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/radiobutton_unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/radiobutton_unchecked.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/res/qss/flatgray/radiobutton_unchecked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/FoxBreatheLabeler/res/qss/flatgray/radiobutton_unchecked_disable.png -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/util/Fbl.h: -------------------------------------------------------------------------------- 1 | #ifndef ASR_H 2 | #define ASR_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include "FblModel.h" 9 | #include 10 | 11 | namespace FBL { 12 | 13 | class FBL { 14 | public: 15 | explicit FBL(const QString &modelDir); 16 | ~FBL(); 17 | 18 | bool recognize(const std::filesystem::path &filepath, std::vector> &res, 19 | std::string &msg, float ap_threshold = 0.4, float ap_dur = 0.08) const; 20 | 21 | private: 22 | std::unique_ptr m_fblModel; 23 | 24 | int m_audio_sample_rate; 25 | int m_hop_size; 26 | 27 | float m_time_scale; 28 | }; 29 | } // LyricFA 30 | 31 | #endif // ASR_H 32 | -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/util/FblModel.cpp: -------------------------------------------------------------------------------- 1 | #include "FblModel.h" 2 | 3 | namespace FBL { 4 | FblModel::FblModel(const std::filesystem::path &model_path) 5 | : m_env(Ort::Env(ORT_LOGGING_LEVEL_WARNING, "FblModel")), m_session_options(Ort::SessionOptions()), 6 | m_session(nullptr) { 7 | 8 | m_input_name = "waveform"; 9 | m_output_name = "ap_probability"; 10 | 11 | #ifdef _WIN32 12 | m_session = new Ort::Session(m_env, model_path.wstring().c_str(), m_session_options); 13 | #else 14 | m_session = new Ort::Session(m_env, model_path.c_str(), m_session_options); 15 | #endif 16 | } 17 | 18 | FblModel::~FblModel() { 19 | delete m_session; 20 | m_input_name = {}; 21 | m_output_name = {}; 22 | } 23 | 24 | bool FblModel::forward(const std::vector> &input_data, std::vector &result, 25 | std::string &msg) const { 26 | const size_t batch_size = input_data.size(); 27 | if (batch_size == 0) { 28 | throw std::invalid_argument("输入数据不能为空。"); 29 | } 30 | 31 | // 确定输入数据中最大的长度 32 | size_t max_height = 0; 33 | for (const auto &channel_data : input_data) { 34 | max_height = std::max(max_height, channel_data.size()); 35 | } 36 | 37 | // 创建一个用于存放扁平化后的输入数据的向量 38 | std::vector flattened_input(batch_size * max_height, 0.0f); 39 | 40 | // 将输入数据扁平化并填充到flattened_input中 41 | for (size_t i = 0; i < batch_size; ++i) { 42 | std::copy(input_data[i].begin(), input_data[i].end(), flattened_input.begin() + i * max_height); 43 | } 44 | 45 | // 定义输入张量的形状 46 | const std::array input_shape_{static_cast(batch_size), static_cast(max_height)}; 47 | 48 | // 创建输入张量 49 | const Ort::Value input_tensor = Ort::Value::CreateTensor( 50 | m_memoryInfo, flattened_input.data(), flattened_input.size(), input_shape_.data(), input_shape_.size()); 51 | 52 | try { 53 | auto output_tensors = 54 | m_session->Run(Ort::RunOptions{nullptr}, &m_input_name, &input_tensor, 1, &m_output_name, 1); 55 | 56 | const float *float_array = output_tensors.front().GetTensorMutableData(); 57 | result = std::vector( 58 | float_array, float_array + output_tensors.front().GetTensorTypeAndShapeInfo().GetElementCount()); 59 | return true; 60 | } catch (const Ort::Exception &e) { 61 | msg = "Error during model inference: " + std::string(e.what()); 62 | return false; 63 | } 64 | } 65 | } // FBL -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/util/FblModel.h: -------------------------------------------------------------------------------- 1 | #ifndef FBLMODEL_H 2 | #define FBLMODEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | namespace FBL { 9 | 10 | class FblModel { 11 | public: 12 | explicit FblModel(const std::filesystem::path &model_path); 13 | ~FblModel(); 14 | bool forward(const std::vector> &input_data, std::vector &result, 15 | std::string &msg) const; 16 | 17 | private: 18 | Ort::Env m_env; 19 | Ort::SessionOptions m_session_options; 20 | Ort::Session *m_session; 21 | Ort::AllocatorWithDefaultOptions m_allocator; 22 | const char *m_input_name; 23 | const char *m_output_name; 24 | 25 | #ifdef _WIN_X86 26 | Ort::MemoryInfo m_memoryInfo = Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU); 27 | #else 28 | Ort::MemoryInfo m_memoryInfo = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); 29 | #endif 30 | }; 31 | 32 | } // FBL 33 | 34 | #endif // FBLMODEL_H 35 | -------------------------------------------------------------------------------- /src/apps/FoxBreatheLabeler/util/FblThread.h: -------------------------------------------------------------------------------- 1 | #ifndef ASRTHREAD_H 2 | #define ASRTHREAD_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "Fbl.h" 10 | 11 | namespace FBL { 12 | class FblThread final : public QObject, public QRunnable { 13 | Q_OBJECT 14 | public: 15 | FblThread(FBL *fbl, QString filename, QString wavPath, QString rawTgPath, QString outTgPath, 16 | float ap_threshold = 0.4, float ap_dur = 0.08, float sp_dur = 0.1); 17 | void run() override; 18 | 19 | private: 20 | FBL *m_asr; 21 | QString m_filename; 22 | QString m_wavPath; 23 | QString m_rawTgPath; 24 | QString m_outTgPath; 25 | 26 | float ap_threshold, ap_dur, sp_dur; 27 | 28 | signals: 29 | void oneFailed(const QString &filename, const QString &msg); 30 | void oneFinished(const QString &filename, const QString &msg); 31 | }; 32 | } 33 | 34 | #endif // ASRTHREAD_H 35 | -------------------------------------------------------------------------------- /src/apps/LyricFA/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(LyricFA VERSION 0.0.0.2) 2 | 3 | set(CMAKE_AUTOMOC ON) 4 | set(CMAKE_AUTORCC ON) 5 | set(CMAKE_AUTOUIC ON) 6 | 7 | file(GLOB_RECURSE _src *.h *.cpp) 8 | add_executable(${PROJECT_NAME} ${_src} res/qss.qrc) 9 | 10 | find_package(SndFile CONFIG REQUIRED) 11 | find_package(cpp-pinyin CONFIG REQUIRED) 12 | 13 | target_link_libraries(${PROJECT_NAME} PRIVATE 14 | Qt${QT_VERSION_MAJOR}::Core 15 | Qt${QT_VERSION_MAJOR}::Widgets 16 | cpp-pinyin::cpp-pinyin 17 | audio-util 18 | FunAsr 19 | ) 20 | 21 | file(GLOB_RECURSE onnx_files ../../libs/onnxruntime/lib/*.*) 22 | foreach (onnx_file ${onnx_files}) 23 | file(COPY ${onnx_file} DESTINATION ${CMAKE_BINARY_DIR}/bin) 24 | endforeach () 25 | 26 | target_compile_definitions(${PROJECT_NAME} PRIVATE 27 | APP_VERSION="${PROJECT_VERSION}" 28 | ) 29 | 30 | target_include_directories(${PROJECT_NAME} PRIVATE .) 31 | 32 | if (WIN32) 33 | include(${PROJECT_CMAKE_MODULES_DIR}/winrc.cmake) 34 | 35 | if (NOT ${CMAKE_BUILD_TYPE} MATCHES "Deb") 36 | set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE) 37 | endif () 38 | endif () 39 | 40 | set(DIRECTORIES_TO_COPY 41 | dict 42 | ) 43 | 44 | if (APPLE) 45 | set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE) 46 | 47 | foreach (dir ${DIRECTORIES_TO_COPY}) 48 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 49 | COMMAND 50 | ${CMAKE_COMMAND} -E copy_directory 51 | ${CMAKE_BINARY_DIR}/bin/${dir} 52 | $/Resources/${dir} 53 | ) 54 | endforeach () 55 | endif () 56 | 57 | set_property(TARGET DeployedTargets APPEND PROPERTY TARGETS ${PROJECT_NAME}) -------------------------------------------------------------------------------- /src/apps/LyricFA/gui/MainWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "../util/Asr.h" 17 | #include "../util/MatchLyric.h" 18 | 19 | namespace LyricFA { 20 | class MainWindow final : public QMainWindow { 21 | Q_OBJECT 22 | public: 23 | explicit MainWindow(QWidget *parent = nullptr); 24 | ~MainWindow() override; 25 | 26 | protected: 27 | QMenu *fileMenu; 28 | QAction *addFileAction; 29 | QAction *addFolderAction; 30 | 31 | QMenu *helpMenu; 32 | QAction *aboutAppAction; 33 | QAction *aboutQtAction; 34 | 35 | QWidget *mainWidget; 36 | QListWidget *taskList; 37 | QVBoxLayout *mainLayout; 38 | QHBoxLayout *listLayout; 39 | QHBoxLayout *btnLayout; 40 | 41 | QPushButton *remove; 42 | QPushButton *clear; 43 | QPushButton *runAsr; 44 | QPushButton *matchLyric; 45 | 46 | QPlainTextEdit *out; 47 | QProgressBar *progressBar; 48 | 49 | QVBoxLayout *rightLayout; 50 | QHBoxLayout *labLayout; 51 | QHBoxLayout *jsonLayout; 52 | QHBoxLayout *lyricLayout; 53 | 54 | QLineEdit *labEdit; 55 | QLineEdit *jsonEdit; 56 | QLineEdit *lyricEdit; 57 | 58 | QCheckBox *pinyinBox; 59 | 60 | QLabel *progressLabel; 61 | QHBoxLayout *progressLayout; 62 | 63 | void addFiles(const QStringList &paths) const; 64 | void addFolder(const QString &path) const; 65 | 66 | void dragEnterEvent(QDragEnterEvent *event) override; 67 | void dropEvent(QDropEvent *event) override; 68 | void closeEvent(QCloseEvent *event) override; 69 | 70 | private: 71 | Asr *m_asr = nullptr; 72 | QSharedPointer m_mandarin = nullptr; 73 | MatchLyric *m_match = nullptr; 74 | 75 | int m_workTotal = 0; 76 | int m_workFinished = 0; 77 | int m_workError = 0; 78 | QStringList m_failIndex; 79 | QThreadPool *m_threadpool; 80 | 81 | static void initStyleSheet(); 82 | 83 | void slot_labPath(); 84 | void slot_jsonPath(); 85 | void slot_lyricPath(); 86 | 87 | void slot_removeListItem() const; 88 | void slot_clearTaskList() const; 89 | void slot_runAsr(); 90 | void slot_matchLyric(); 91 | 92 | void slot_oneFailed(const QString &filename, const QString &msg); 93 | void slot_oneFinished(const QString &filename, const QString &msg); 94 | void slot_threadFinished(); 95 | 96 | void _q_fileMenuTriggered(const QAction *action); 97 | void _q_helpMenuTriggered(const QAction *action); 98 | }; 99 | } 100 | #endif // MAINWINDOW_H 101 | -------------------------------------------------------------------------------- /src/apps/LyricFA/main.cpp: -------------------------------------------------------------------------------- 1 | #include "gui/MainWindow.h" 2 | #include 3 | 4 | #ifdef Q_OS_WIN 5 | # include 6 | #endif 7 | 8 | using namespace LyricFA; 9 | int main(int argc, char *argv[]) { 10 | QApplication a(argc, argv); 11 | 12 | #ifdef Q_OS_WIN 13 | // For Windows only. 14 | // Use Win32 API to retrieve the non-client metrics, including the system text font. 15 | // If success, set application font to system text font. 16 | NONCLIENTMETRICSW metrics = {sizeof(NONCLIENTMETRICSW)}; 17 | if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &metrics, 0)) { 18 | // Get font properties, and construct a `QFont` object 19 | // Font face 20 | QString fontFace = QString::fromWCharArray(metrics.lfMessageFont.lfFaceName); 21 | 22 | // Font point size 23 | qreal fontPointSize = 0.0; 24 | if (HDC hDC = GetDC(nullptr)) { 25 | // To get font point size, we first get font height (in logical units) and device DPI, 26 | // then calculate the point size. 27 | // Here, we use message text font. 28 | // Reference: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-logfontw 29 | int dpiY = GetDeviceCaps(hDC, LOGPIXELSY); 30 | fontPointSize = -72.0 * metrics.lfMessageFont.lfHeight / dpiY; 31 | ReleaseDC(nullptr, hDC); 32 | } 33 | 34 | QFont font(fontFace); 35 | if (fontPointSize > 0) { 36 | font.setPointSizeF(fontPointSize); 37 | } 38 | qApp->setFont(font); 39 | } 40 | #endif 41 | 42 | MainWindow w; 43 | w.show(); 44 | return QApplication::exec(); 45 | } 46 | -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qss/flatgray.css 4 | qss/flatgray/add_bottom.png 5 | qss/flatgray/add_left.png 6 | qss/flatgray/add_right.png 7 | qss/flatgray/add_top.png 8 | qss/flatgray/arrow_bottom.png 9 | qss/flatgray/arrow_left.png 10 | qss/flatgray/arrow_right.png 11 | qss/flatgray/arrow_top.png 12 | qss/flatgray/branch_close.png 13 | qss/flatgray/branch_open.png 14 | qss/flatgray/calendar_nextmonth.png 15 | qss/flatgray/calendar_prevmonth.png 16 | qss/flatgray/checkbox_checked.png 17 | qss/flatgray/checkbox_checked_disable.png 18 | qss/flatgray/checkbox_parcial.png 19 | qss/flatgray/checkbox_parcial_disable.png 20 | qss/flatgray/checkbox_unchecked.png 21 | qss/flatgray/checkbox_unchecked_disable.png 22 | qss/flatgray/menu_checked.png 23 | qss/flatgray/radiobutton_checked.png 24 | qss/flatgray/radiobutton_checked_disable.png 25 | qss/flatgray/radiobutton_unchecked.png 26 | qss/flatgray/radiobutton_unchecked_disable.png 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/add_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/add_bottom.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/add_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/add_left.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/add_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/add_right.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/add_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/add_top.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/arrow_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/arrow_bottom.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/arrow_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/arrow_left.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/arrow_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/arrow_right.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/arrow_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/arrow_top.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/branch_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/branch_close.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/branch_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/branch_open.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/calendar_nextmonth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/calendar_nextmonth.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/calendar_prevmonth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/calendar_prevmonth.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/checkbox_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/checkbox_checked.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/checkbox_checked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/checkbox_checked_disable.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/checkbox_parcial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/checkbox_parcial.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/checkbox_parcial_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/checkbox_parcial_disable.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/checkbox_unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/checkbox_unchecked.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/checkbox_unchecked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/checkbox_unchecked_disable.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/menu_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/menu_checked.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/radiobutton_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/radiobutton_checked.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/radiobutton_checked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/radiobutton_checked_disable.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/radiobutton_unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/radiobutton_unchecked.png -------------------------------------------------------------------------------- /src/apps/LyricFA/res/qss/flatgray/radiobutton_unchecked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/LyricFA/res/qss/flatgray/radiobutton_unchecked_disable.png -------------------------------------------------------------------------------- /src/apps/LyricFA/util/Asr.cpp: -------------------------------------------------------------------------------- 1 | #include "Asr.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace LyricFA { 14 | 15 | Asr::Asr(const QString &modelPath) { 16 | m_asrHandle = std::unique_ptr(FunAsr::create_model(modelPath.toUtf8().toStdString().c_str(), 4)); 17 | 18 | if (!m_asrHandle) { 19 | qDebug() << "Cannot load ASR Model, there must be files model.onnx and vocab.txt"; 20 | } 21 | } 22 | 23 | Asr::~Asr() = default; 24 | 25 | bool Asr::recognize(const std::filesystem::path &filepath, std::string &msg) const { 26 | if (!m_asrHandle) { 27 | return false; 28 | } 29 | auto sf_vio = AudioUtil::resample_to_vio(filepath, msg, 1, 16000); 30 | 31 | SndfileHandle sf(sf_vio.vio, &sf_vio.data, SFM_READ, SF_FORMAT_WAV | SF_FORMAT_PCM_16, 1, 16000); 32 | const auto totalSize = sf.frames(); 33 | 34 | std::vector audio(totalSize); 35 | sf.seek(0, SEEK_SET); 36 | sf.read(audio.data(), static_cast(audio.size())); 37 | 38 | const AudioUtil::Slicer slicer(160, 0.02f, 160, 160 * 4, 500, 30, 50); 39 | const auto chunks = slicer.slice(audio); 40 | 41 | if (chunks.empty()) { 42 | msg = "slicer: no audio chunks for output!"; 43 | return false; 44 | } 45 | 46 | int idx = 0; 47 | 48 | for (const auto &[fst, snd] : chunks) { 49 | const auto beginFrame = fst; 50 | const auto endFrame = snd; 51 | const auto frameCount = endFrame - beginFrame; 52 | if (frameCount <= 0 || beginFrame > totalSize || endFrame > totalSize) { 53 | continue; 54 | } 55 | 56 | sf.seek(beginFrame, SEEK_SET); 57 | std::vector tmp(frameCount); 58 | const auto bytesWritten = sf.read(tmp.data(), static_cast(tmp.size())); 59 | 60 | if (bytesWritten > 60 * 16000) { 61 | msg = "The audio contains continuous pronunciation segments that exceed 60 seconds. Please manually " 62 | "segment and rerun the recognition program."; 63 | return false; 64 | } 65 | 66 | FunAsr::Audio asr_audio(1); 67 | asr_audio.loadPcmFloat(tmp.data(), static_cast(tmp.size())); 68 | 69 | float *buff; 70 | int len; 71 | int flag = 0; 72 | while (asr_audio.fetch(buff, len, flag) > 0) { 73 | m_asrHandle->reset(); 74 | msg += m_asrHandle->forward(buff, len, flag); 75 | } 76 | idx++; 77 | } 78 | 79 | 80 | if (msg.empty()) { 81 | msg = "Asr fail."; 82 | return false; 83 | } 84 | return true; 85 | } 86 | } // LyricFA -------------------------------------------------------------------------------- /src/apps/LyricFA/util/Asr.h: -------------------------------------------------------------------------------- 1 | #ifndef ASR_H 2 | #define ASR_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | 12 | namespace LyricFA { 13 | 14 | class Asr { 15 | public: 16 | explicit Asr(const QString &modelPath); 17 | ~Asr(); 18 | 19 | bool recognize(const std::filesystem::path &filepath, std::string &msg) const; 20 | 21 | private: 22 | std::unique_ptr m_asrHandle; 23 | }; 24 | } // LyricFA 25 | 26 | #endif // ASR_H 27 | -------------------------------------------------------------------------------- /src/apps/LyricFA/util/AsrThread.cpp: -------------------------------------------------------------------------------- 1 | #include "AsrThread.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace LyricFA { 8 | AsrThread::AsrThread(Asr *asr, QString filename, QString wavPath, QString labPath, 9 | const QSharedPointer &g2p) 10 | : m_asr(asr), m_filename(std::move(filename)), m_wavPath(std::move(wavPath)), m_labPath(std::move(labPath)), 11 | m_g2p(g2p) { 12 | } 13 | 14 | void AsrThread::run() { 15 | std::string asrMsg; 16 | const auto asrRes = m_asr->recognize(m_wavPath.toLocal8Bit().toStdString(), asrMsg); 17 | 18 | if (!asrRes) { 19 | Q_EMIT this->oneFailed(m_filename, QString::fromStdString(asrMsg)); 20 | return; 21 | } 22 | 23 | QFile labFile(m_labPath.toLocal8Bit()); 24 | if (!labFile.open(QIODevice::WriteOnly | QIODevice::Text)) { 25 | QMessageBox::critical(nullptr, QApplication::applicationName(), 26 | QString("Failed to write to file %1").arg(m_labPath)); 27 | return; 28 | } 29 | 30 | QTextStream labIn(&labFile); 31 | if (m_g2p) { 32 | const auto g2pRes = m_g2p->hanziToPinyin(asrMsg, Pinyin::ManTone::NORMAL, Pinyin::Error::Default, true); 33 | asrMsg = g2pRes.toStdStr(); 34 | } 35 | 36 | labIn << QString::fromStdString(asrMsg); 37 | labFile.close(); 38 | Q_EMIT this->oneFinished(m_filename, QString::fromStdString(asrMsg)); 39 | } 40 | } -------------------------------------------------------------------------------- /src/apps/LyricFA/util/AsrThread.h: -------------------------------------------------------------------------------- 1 | #ifndef ASRTHREAD_H 2 | #define ASRTHREAD_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include "Asr.h" 12 | 13 | namespace LyricFA { 14 | class AsrThread final : public QObject, public QRunnable { 15 | Q_OBJECT 16 | public: 17 | AsrThread(Asr *asr, QString filename, QString wavPath, QString labPath, 18 | const QSharedPointer &g2p); 19 | void run() override; 20 | 21 | private: 22 | Asr *m_asr; 23 | QString m_filename; 24 | QString m_wavPath; 25 | QString m_labPath; 26 | QSharedPointer m_g2p = nullptr; 27 | 28 | signals: 29 | void oneFailed(const QString &filename, const QString &msg); 30 | void oneFinished(const QString &filename, const QString &msg); 31 | }; 32 | } 33 | 34 | #endif // ASRTHREAD_H 35 | -------------------------------------------------------------------------------- /src/apps/LyricFA/util/FaTread.cpp: -------------------------------------------------------------------------------- 1 | #include "FaTread.h" 2 | 3 | #include 4 | 5 | namespace LyricFA { 6 | FaTread::FaTread(MatchLyric *match, QString filename, QString labPath, QString jsonPath, const bool &asr_rectify) 7 | : m_match(match), m_filename(std::move(filename)), m_labPath(std::move(labPath)), 8 | m_jsonPath(std::move(jsonPath)), m_asr_rectify(asr_rectify) { 9 | } 10 | 11 | void FaTread::run() { 12 | QString matchMsg; 13 | const auto matchRes = m_match->match(m_filename, m_labPath, m_jsonPath, matchMsg, m_asr_rectify); 14 | 15 | if (!matchRes) { 16 | Q_EMIT this->oneFailed(m_filename, matchMsg); 17 | return; 18 | } 19 | Q_EMIT this->oneFinished(m_filename, matchMsg); 20 | } 21 | 22 | } // LyricFA -------------------------------------------------------------------------------- /src/apps/LyricFA/util/FaTread.h: -------------------------------------------------------------------------------- 1 | #ifndef FATREAD_H 2 | #define FATREAD_H 3 | 4 | #include 5 | #include 6 | 7 | #include "MatchLyric.h" 8 | 9 | namespace LyricFA { 10 | 11 | class FaTread final : public QObject, public QRunnable { 12 | Q_OBJECT 13 | public: 14 | FaTread(MatchLyric *match, QString filename, QString labPath, QString jsonPath, const bool &asr_rectify = true); 15 | void run() override; 16 | 17 | private: 18 | MatchLyric *m_match; 19 | QString m_filename; 20 | QString m_labPath; 21 | QString m_jsonPath; 22 | bool m_asr_rectify; 23 | 24 | signals: 25 | void oneFailed(const QString &filename, const QString &msg); 26 | void oneFinished(const QString &filename, const QString &msg); 27 | }; 28 | 29 | } // LyricFA 30 | 31 | #endif // FATREAD_H 32 | -------------------------------------------------------------------------------- /src/apps/LyricFA/util/LevenshteinDistance.h: -------------------------------------------------------------------------------- 1 | #ifndef LEVENSHTEINDISTANCE_H 2 | #define LEVENSHTEINDISTANCE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace LyricFA { 9 | struct MatchRes { 10 | int start = 0; 11 | int end = 0; 12 | QStringList textDiff; 13 | QStringList pinyinDiff; 14 | }; 15 | 16 | struct StepPair { 17 | QString raw; 18 | QString res; 19 | }; 20 | 21 | struct CalcuRes { 22 | int edit_distance; 23 | QStringList text_res, pinyin_res; 24 | QList corresponding_texts, corresponding_characters; 25 | }; 26 | 27 | struct FaRes { 28 | QStringList match_text, match_pinyin, text_step, pinyin_step; 29 | }; 30 | 31 | typedef QVector> matrix; 32 | 33 | class LevenshteinDistance final : public QObject { 34 | Q_OBJECT 35 | public: 36 | LevenshteinDistance() = default; 37 | ~LevenshteinDistance() override = default; 38 | static FaRes find_similar_substrings(const QStringList &target, const QStringList &pinyin_list, 39 | QStringList text_list = {}, const bool &del_tip = false, 40 | const bool &ins_tip = false, const bool &sub_tip = false); 41 | 42 | private: 43 | static MatchRes find_best_matches(const QStringList &text_list, const QStringList &source_list, 44 | const QStringList &sub_list); 45 | static QStringList fill_step_out(const QList &pairs, const bool &del_tip, const bool &ins_tip, 46 | const bool &sub_tip); 47 | static matrix init_dp_matrix(const int &m, const int &n, const int &del_cost, const int &ins_cost); 48 | static int calculate_edit_distance_dp(matrix dp, const QStringList &substring, const QStringList &target, 49 | const bool &del_cost, const bool &ins_cost, const bool &sub_cost); 50 | static QPair, QList> backtrack_corresponding(matrix dp, const QStringList &text, 51 | const QStringList &substring, 52 | const QStringList &target); 53 | static CalcuRes calculate_edit_distance(const QStringList &_text, const QStringList &substring, 54 | const QStringList &target, const int &del_cost = 1, 55 | const int &ins_cost = 3, const int &sub_cost = 6); 56 | static CalcuRes findMinEditDistance(const QList &similar_substrings); 57 | }; 58 | } 59 | #endif // LEVENSHTEINDISTANCE_H 60 | -------------------------------------------------------------------------------- /src/apps/LyricFA/util/MatchLyric.h: -------------------------------------------------------------------------------- 1 | #ifndef MATCHLYRIC_H 2 | #define MATCHLYRIC_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace LyricFA { 12 | class MatchLyric { 13 | public: 14 | MatchLyric(); 15 | ~MatchLyric(); 16 | 17 | void initLyric(const QString &lyric_folder); 18 | 19 | bool match(const QString &filename, const QString &labPath, const QString &jsonPath, QString &msg, 20 | const bool &asr_rectify = true) const; 21 | 22 | private: 23 | struct lyricInfo { 24 | QStringList text, pinyin; 25 | }; 26 | 27 | QMap m_lyricDict; 28 | std::unique_ptr m_mandarin; 29 | }; 30 | } 31 | #endif // MATCHLYRIC_H 32 | -------------------------------------------------------------------------------- /src/apps/LyricFA/util/MathUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef LYRICFA_MATHUTILS_H 2 | #define LYRICFA_MATHUTILS_H 3 | 4 | template 5 | inline T divIntRound(T n, T d); 6 | 7 | template 8 | inline T divIntRound(T n, T d) { 9 | /* 10 | * Integer division rounding to the closest integer, without converting to floating point numbers. 11 | */ 12 | // T should be an integer type (int, int64_t, qint64, ...) 13 | return n < 0 ^ d < 0 ? (n - d / 2) / d : (n + d / 2) / d; 14 | } 15 | 16 | #endif // LYRICFA_MATHUTILS_H 17 | -------------------------------------------------------------------------------- /src/apps/MinLabel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(MinLabel VERSION 0.0.1.8) 2 | 3 | set(CMAKE_AUTOMOC ON) 4 | set(CMAKE_AUTORCC ON) 5 | set(CMAKE_AUTOUIC ON) 6 | 7 | file(GLOB_RECURSE _src *.h *.cpp) 8 | add_executable(${PROJECT_NAME} ${_src} res.qrc res/qss.qrc) 9 | 10 | find_package(cpp-pinyin CONFIG REQUIRED) 11 | find_package(cpp-kana CONFIG REQUIRED) 12 | 13 | target_link_libraries(${PROJECT_NAME} PRIVATE 14 | Qt${QT_VERSION_MAJOR}::Core 15 | Qt${QT_VERSION_MAJOR}::Widgets 16 | cpp-pinyin::cpp-pinyin 17 | cpp-kana::cpp-kana 18 | SDLPlayback FFmpegDecoder 19 | ) 20 | 21 | target_compile_definitions(${PROJECT_NAME} PRIVATE 22 | APP_VERSION="${PROJECT_VERSION}" 23 | ) 24 | 25 | target_include_directories(${PROJECT_NAME} PRIVATE .) 26 | 27 | if (WIN32) 28 | include(${PROJECT_CMAKE_MODULES_DIR}/winrc.cmake) 29 | 30 | if (NOT ${CMAKE_BUILD_TYPE} MATCHES "Deb") 31 | set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE) 32 | endif () 33 | endif () 34 | 35 | if (APPLE) 36 | set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE) 37 | endif () 38 | 39 | set(DIRECTORIES_TO_COPY 40 | qss 41 | ) 42 | 43 | foreach (dir ${DIRECTORIES_TO_COPY}) 44 | if (APPLE) 45 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 46 | COMMAND 47 | ${CMAKE_COMMAND} -E copy_directory 48 | ${CMAKE_CURRENT_SOURCE_DIR}/res/${dir} 49 | $/Resources/${dir} 50 | ) 51 | else () 52 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 53 | COMMAND 54 | ${CMAKE_COMMAND} -E copy_directory 55 | ${CMAKE_CURRENT_SOURCE_DIR}/res/${dir} 56 | $/${dir} 57 | ) 58 | 59 | install( 60 | DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/res/${dir} 61 | DESTINATION . 62 | ) 63 | endif () 64 | endforeach () 65 | 66 | if (WIN32) 67 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 68 | COMMAND ${CMAKE_COMMAND} -E copy_directory 69 | ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/cpp-pinyin/dict 70 | ${CMAKE_BINARY_DIR}/bin/dict 71 | ) 72 | 73 | install(DIRECTORY ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/cpp-pinyin/dict 74 | DESTINATION . 75 | ) 76 | endif () 77 | 78 | set_property(TARGET DeployedTargets APPEND PROPERTY TARGETS ${PROJECT_NAME}) -------------------------------------------------------------------------------- /src/apps/MinLabel/gui/Common.h: -------------------------------------------------------------------------------- 1 | #ifndef DATASET_TOOLS_COMMON_H 2 | #define DATASET_TOOLS_COMMON_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | QString audioToOtherSuffix(const QString &filename, const QString &tarSuffix); 9 | QString labFileToAudioFile(const QString &filename); 10 | 11 | struct ExportInfo { 12 | QString outputDir; 13 | QString folderName; 14 | bool exportAudio; 15 | bool labFile; 16 | bool rawText; 17 | bool removeTone; 18 | }; 19 | 20 | struct CopyInfo { 21 | QString rawName; 22 | QString tarName; 23 | QString sourceDir; 24 | QString targetDir; 25 | QString tarBasename; 26 | bool exist; 27 | 28 | CopyInfo(QString rawName, const QString &tarName, QString sourceDir, QString targetDir, bool isExist) 29 | : rawName(std::move(rawName)), tarName(tarName), sourceDir(std::move(sourceDir)), 30 | targetDir(std::move(targetDir)), exist(isExist) { 31 | const QString filename = QFileInfo(tarName).fileName(); 32 | const QString suffix = QFileInfo(tarName).suffix(); 33 | tarBasename = filename.mid(0, filename.size() - suffix.size() - 1); 34 | } 35 | }; 36 | 37 | bool copyFile(QList ©List, const ExportInfo &exportInfo); 38 | int jsonCount(const QString &dirName); 39 | void mkdir(const ExportInfo &exportInfo); 40 | QList mkCopylist(const QString &sourcePath, const QString &outputDir); 41 | bool readJsonFile(const QString &fileName, QJsonObject &jsonObject); 42 | bool writeJsonFile(const QString &fileName, const QJsonObject &jsonObject); 43 | #endif // DATASET_TOOLS_COMMON_H 44 | -------------------------------------------------------------------------------- /src/apps/MinLabel/gui/ExportDialog.cpp: -------------------------------------------------------------------------------- 1 | #include "ExportDialog.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | ExportDialog::ExportDialog(QWidget *parent) : QDialog(parent) { 13 | setWindowTitle("Export"); 14 | 15 | auto *layout = new QFormLayout(this); 16 | 17 | outputDirEdit = new QLineEdit(this); 18 | outputDirEdit->setText(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); 19 | outputDirButton = new QPushButton("...", this); 20 | outputDirButton->setMaximumWidth(100); 21 | 22 | connect(outputDirButton, &QPushButton::clicked, this, [=] { 23 | const QString dirname = QFileDialog::getExistingDirectory(this, "Select Directory", outputDirEdit->text()); 24 | if (!dirname.isEmpty()) { 25 | outputDirEdit->setText(dirname); 26 | } 27 | }); 28 | 29 | const auto hLayout = new QHBoxLayout(); 30 | hLayout->addWidget(outputDirEdit); 31 | hLayout->addWidget(outputDirButton); 32 | 33 | layout->addRow(new QLabel("Out Directory:", this)); 34 | layout->addRow(hLayout); 35 | 36 | folderNameEdit = new QLineEdit(this); 37 | folderNameEdit->setText("minlabel_export"); 38 | layout->addRow(new QLabel("Output Folder Name:", this), folderNameEdit); 39 | 40 | expAudio = new QCheckBox("Export audio", this); 41 | expAudio->setChecked(true); 42 | layout->addRow(expAudio); 43 | 44 | labFile = new QCheckBox("Export word sequences(*.lab)", this); 45 | labFile->setChecked(true); 46 | layout->addRow(labFile); 47 | 48 | rawText = new QCheckBox("Export raw text(*.txt)", this); 49 | layout->addRow(rawText); 50 | 51 | removeTone = new QCheckBox("Export word sequences without tone(*.lab)", this); 52 | layout->addRow(removeTone); 53 | 54 | auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 55 | layout->addRow(buttonBox); 56 | connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 57 | connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 58 | 59 | connect(this, &QDialog::accepted, this, [=] { 60 | exportInfo.outputDir = outputDirEdit->text(); 61 | exportInfo.folderName = folderNameEdit->text(); 62 | exportInfo.exportAudio = expAudio->isChecked(); 63 | exportInfo.labFile = labFile->isChecked(); 64 | exportInfo.rawText = rawText->isChecked(); 65 | exportInfo.removeTone = removeTone->isChecked(); 66 | }); 67 | 68 | resize(500, 300); 69 | } 70 | 71 | ExportDialog::~ExportDialog() = default; 72 | -------------------------------------------------------------------------------- /src/apps/MinLabel/gui/ExportDialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DATASET_TOOLS_EXPORTDIALOG_H 2 | #define DATASET_TOOLS_EXPORTDIALOG_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Common.h" 10 | 11 | class ExportDialog final : public QDialog { 12 | Q_OBJECT 13 | public: 14 | explicit ExportDialog(QWidget *parent = nullptr); 15 | ~ExportDialog() override; 16 | 17 | ExportInfo exportInfo; 18 | 19 | QLineEdit *outputDirEdit; 20 | QPushButton *outputDirButton; 21 | 22 | QLineEdit *folderNameEdit; 23 | QCheckBox *convertFilename{}; 24 | QCheckBox *expAudio; 25 | QCheckBox *labFile; 26 | QCheckBox *rawText; 27 | QCheckBox *removeTone; 28 | }; 29 | 30 | 31 | #endif // DATASET_TOOLS_EXPORTDIALOG_H 32 | -------------------------------------------------------------------------------- /src/apps/MinLabel/gui/MainWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Common.h" 10 | #include "PlayWidget.h" 11 | #include "TextWidget.h" 12 | 13 | class MainWindow final : public QMainWindow { 14 | Q_OBJECT 15 | public: 16 | explicit MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow() override; 18 | 19 | protected: 20 | QMenu *fileMenu; 21 | QAction *browseAction; 22 | QAction *covertAction; 23 | QAction *exportAction; 24 | 25 | QMenu *editMenu; 26 | QAction *nextAction; 27 | QAction *prevAction; 28 | 29 | QMenu *playMenu; 30 | QAction *playAction; 31 | 32 | QMenu *helpMenu; 33 | QAction *aboutAppAction; 34 | QAction *aboutQtAction; 35 | 36 | bool playing; 37 | QString dirname; 38 | 39 | PlayWidget *playerWidget; 40 | TextWidget *textWidget; 41 | 42 | QTreeView *treeView; 43 | QFileSystemModel *fsModel; 44 | 45 | QProgressBar *progressBar; 46 | 47 | QSplitter *mainSplitter; 48 | 49 | QVBoxLayout *rightLayout; 50 | QLabel *progressLabel; 51 | QHBoxLayout *progressLayout; 52 | QWidget *rightWidget; 53 | 54 | QString lastFile; 55 | 56 | QSettings *cfg{}; 57 | 58 | void openDirectory(const QString &dirName) const; 59 | void openFile(const QString &filename) const; 60 | void saveFile(const QString &filename); 61 | void labToJson(const QString &dirName); 62 | void exportAudio(const ExportInfo &exportInfo); 63 | 64 | void reloadWindowTitle(); 65 | 66 | void dragEnterEvent(QDragEnterEvent *event) override; 67 | void dropEvent(QDropEvent *event) override; 68 | void closeEvent(QCloseEvent *event) override; 69 | 70 | private: 71 | static void initStyleSheet(); 72 | void applyConfig(); 73 | 74 | void _q_fileMenuTriggered(const QAction *action); 75 | void _q_editMenuTriggered(const QAction *action) const; 76 | void _q_playMenuTriggered(const QAction *action) const; 77 | void _q_helpMenuTriggered(const QAction *action); 78 | void _q_updateProgress() const; 79 | void _q_treeCurrentChanged(const QModelIndex ¤t); 80 | }; 81 | 82 | #endif // MAINWINDOW_H 83 | -------------------------------------------------------------------------------- /src/apps/MinLabel/gui/PlayWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef PLAYWIDGET_H 2 | #define PLAYWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "Api/IAudioDecoder.h" 13 | #include "Api/IAudioPlayback.h" 14 | 15 | class PlayWidget : public QWidget { 16 | Q_OBJECT 17 | public: 18 | explicit PlayWidget(QWidget *parent = nullptr); 19 | ~PlayWidget() override; 20 | 21 | void openFile(const QString &filename); 22 | 23 | bool isPlaying() const; 24 | void setPlaying(bool playing); 25 | 26 | protected: 27 | QsApi::IAudioDecoder *decoder{}; 28 | QsApi::IAudioPlayback *playback{}; 29 | 30 | QMenu *deviceMenu; 31 | QActionGroup *deviceActionGroup; 32 | 33 | int notifyTimerId; 34 | bool playing; 35 | QString filename; 36 | 37 | QLabel *fileLabel; 38 | QSlider *slider; 39 | QLabel *timeLabel; 40 | 41 | QPushButton *playButton; 42 | QPushButton *stopButton; 43 | QPushButton *devButton; 44 | 45 | QVBoxLayout *mainLayout; 46 | QHBoxLayout *buttonsLayout; 47 | 48 | void timerEvent(QTimerEvent *event) override; 49 | 50 | private: 51 | void initPlugins(); 52 | void uninitPlugins() const; 53 | 54 | void reloadDevices() const; 55 | void reloadButtonStatus() const; 56 | void reloadSliderStatus() const; 57 | void reloadDeviceActionStatus() const; 58 | 59 | void _q_playButtonClicked(); 60 | void _q_stopButtonClicked(); 61 | void _q_devButtonClicked() const; 62 | void _q_sliderReleased(); 63 | void _q_deviceActionTriggered(const QAction *action); 64 | void _q_playStateChanged(); 65 | void _q_audioDeviceChanged() const; 66 | void _q_audioDeviceAdded() const; 67 | void _q_audioDeviceRemoved() const; 68 | }; 69 | 70 | #endif // PLAYWIDGET_H 71 | -------------------------------------------------------------------------------- /src/apps/MinLabel/gui/TextWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTWIDGET_H 2 | #define TEXTWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | class TextWidget final : public QWidget { 15 | Q_OBJECT 16 | public: 17 | explicit TextWidget(QWidget *parent = nullptr); 18 | ~TextWidget() override; 19 | 20 | QLineEdit *wordsText; 21 | QPlainTextEdit *contentText; 22 | 23 | protected: 24 | QPushButton *replaceButton; 25 | QPushButton *appendButton; 26 | QPushButton *pasteButton; 27 | 28 | QComboBox *languageCombo; 29 | 30 | QCheckBox *covertNum; 31 | QCheckBox *cleanRes; 32 | 33 | QCheckBox *manTone; 34 | QCheckBox *canTone; 35 | QCheckBox *removeArpabetNum; 36 | QCheckBox *removeSokuon; 37 | QCheckBox *doubleConsonant; 38 | 39 | QAction *replaceAction; 40 | 41 | QHBoxLayout *lineLayout; 42 | QHBoxLayout *buttonsLayout; 43 | QHBoxLayout *optionsLayout; 44 | QVBoxLayout *mainLayout; 45 | 46 | QScopedPointer g2p_man; 47 | QScopedPointer g2p_canton; 48 | 49 | private: 50 | QString sentence() const; 51 | 52 | void _q_textToPronunciation(const bool append = false) const; 53 | 54 | void _q_pasteButtonClicked() const; 55 | void _q_onLanguageComboIndexChanged(); 56 | }; 57 | 58 | #endif // TEXTWIDGET_H 59 | -------------------------------------------------------------------------------- /src/apps/MinLabel/main.cpp: -------------------------------------------------------------------------------- 1 | #include "gui/MainWindow.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #ifdef Q_OS_WINDOWS 8 | # include 9 | # include 10 | #endif 11 | 12 | bool isUserRoot() { 13 | #ifdef Q_OS_WINDOWS 14 | return IsUserAnAdmin(); 15 | #else 16 | return geteuid() == 0; 17 | #endif 18 | } 19 | 20 | int main(int argc, char *argv[]) { 21 | QApplication a(argc, argv); 22 | 23 | if (isUserRoot() && !QApplication::arguments().contains("--allow-root")) { 24 | QString title = QApplication::applicationName(); 25 | QString msg = QString("You're trying to start %1 as the %2, which may cause " 26 | "security problem and isn't recommended.") 27 | .arg(QApplication::applicationName(), "Administrator"); 28 | #ifdef Q_OS_WINDOWS 29 | MessageBoxW(nullptr, msg.toStdWString().data(), title.toStdWString().data(), 30 | MB_OK | MB_TOPMOST | MB_SETFOREGROUND | MB_ICONWARNING); 31 | #elif defined(Q_OS_LINUX) 32 | fputs(qPrintable(msg), stdout); 33 | #else 34 | QMessageBox::warning(nullptr, title, msg, QApplication::tr("Confirm")); 35 | #endif 36 | return 0; 37 | } 38 | 39 | #ifdef Q_OS_WINDOWS 40 | QFont f("Microsoft YaHei"); 41 | f.setPointSize(9); 42 | QApplication::setFont(f); 43 | #endif 44 | 45 | #ifdef Q_OS_MAC 46 | Pinyin::setDictionaryPath(QApplication::applicationDirPath().toUtf8().toStdString() + "/../Resources/dict"); 47 | #else 48 | Pinyin::setDictionaryPath(QApplication::applicationDirPath().toUtf8().toStdString() + "/dict"); 49 | #endif 50 | 51 | MainWindow w; 52 | w.show(); 53 | 54 | return QApplication::exec(); 55 | } 56 | -------------------------------------------------------------------------------- /src/apps/MinLabel/res.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | res/pause.svg 4 | res/play.svg 5 | res/stop.svg 6 | res/app.qss 7 | res/audio.svg 8 | res/clipboard.svg 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/apps/MinLabel/res/app.qss: -------------------------------------------------------------------------------- 1 | QSlider:horizontal { 2 | height: 30px; 3 | } 4 | QSlider::groove:horizontal { 5 | height: 20px; 6 | background: #005A9E; 7 | } 8 | 9 | QSlider::groove:vertical { 10 | width: 5px; 11 | background: #005A9E; 12 | } 13 | 14 | QSlider::handle:horizontal { 15 | background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1, stop: 0 #b4b4b4, stop: 1 #8f8f8f); 16 | border: 1px solid #5c5c5c; 17 | width: 15px; 18 | margin: -5px 0; 19 | /* border-radius: 10px; */ 20 | } 21 | 22 | QSlider::handle:vertical { 23 | background: qlineargradient(x1: 1, y1: 1, x2: 0, y2: 0, stop: 0 #b4b4b4, stop: 1 #8f8f8f); 24 | border: 1px solid #5c5c5c; 25 | height: 14px; 26 | margin: 0 -5px; 27 | border-radius: 7px; 28 | } 29 | 30 | QSlider::add-page:horizontal { 31 | background: #868686; 32 | } 33 | 34 | QSlider::add-page:vertical { 35 | background: #868686; 36 | } 37 | 38 | QSlider::sub-page:horizontal { 39 | background: #005A9E; 40 | } 41 | 42 | QSlider::sub-page:vertical { 43 | background: #005A9E; 44 | } 45 | 46 | QPushButton[type=user] { 47 | padding: 5px; 48 | } 49 | 50 | QLineEdit { 51 | padding: 5px; 52 | } 53 | 54 | QPlainTextEdit { 55 | background-color: white; 56 | padding: 5px; 57 | } -------------------------------------------------------------------------------- /src/apps/MinLabel/res/audio.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/apps/MinLabel/res/clipboard.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/apps/MinLabel/res/pause.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/apps/MinLabel/res/play.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qss/flatgray.css 4 | qss/flatgray/add_bottom.png 5 | qss/flatgray/add_left.png 6 | qss/flatgray/add_right.png 7 | qss/flatgray/add_top.png 8 | qss/flatgray/arrow_bottom.png 9 | qss/flatgray/arrow_left.png 10 | qss/flatgray/arrow_right.png 11 | qss/flatgray/arrow_top.png 12 | qss/flatgray/branch_close.png 13 | qss/flatgray/branch_open.png 14 | qss/flatgray/calendar_nextmonth.png 15 | qss/flatgray/calendar_prevmonth.png 16 | qss/flatgray/checkbox_checked.png 17 | qss/flatgray/checkbox_checked_disable.png 18 | qss/flatgray/checkbox_parcial.png 19 | qss/flatgray/checkbox_parcial_disable.png 20 | qss/flatgray/checkbox_unchecked.png 21 | qss/flatgray/checkbox_unchecked_disable.png 22 | qss/flatgray/menu_checked.png 23 | qss/flatgray/radiobutton_checked.png 24 | qss/flatgray/radiobutton_checked_disable.png 25 | qss/flatgray/radiobutton_unchecked.png 26 | qss/flatgray/radiobutton_unchecked_disable.png 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/add_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/add_bottom.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/add_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/add_left.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/add_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/add_right.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/add_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/add_top.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/arrow_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/arrow_bottom.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/arrow_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/arrow_left.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/arrow_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/arrow_right.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/arrow_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/arrow_top.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/branch_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/branch_close.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/branch_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/branch_open.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/calendar_nextmonth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/calendar_nextmonth.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/calendar_prevmonth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/calendar_prevmonth.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/checkbox_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/checkbox_checked.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/checkbox_checked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/checkbox_checked_disable.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/checkbox_parcial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/checkbox_parcial.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/checkbox_parcial_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/checkbox_parcial_disable.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/checkbox_unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/checkbox_unchecked.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/checkbox_unchecked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/checkbox_unchecked_disable.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/menu_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/menu_checked.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/radiobutton_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/radiobutton_checked.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/radiobutton_checked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/radiobutton_checked_disable.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/radiobutton_unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/radiobutton_unchecked.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/qss/flatgray/radiobutton_unchecked_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/apps/MinLabel/res/qss/flatgray/radiobutton_unchecked_disable.png -------------------------------------------------------------------------------- /src/apps/MinLabel/res/stop.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/apps/SlurCutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(SlurCutter VERSION 0.0.1.4) 2 | 3 | set(CMAKE_AUTOMOC ON) 4 | set(CMAKE_AUTORCC ON) 5 | set(CMAKE_AUTOUIC ON) 6 | 7 | file(GLOB_RECURSE _src *.h *.cpp) 8 | add_executable(${PROJECT_NAME} ${_src} res.qrc) 9 | 10 | target_link_libraries(${PROJECT_NAME} PRIVATE 11 | Qt${QT_VERSION_MAJOR}::Core 12 | Qt${QT_VERSION_MAJOR}::Widgets 13 | SDLPlayback FFmpegDecoder 14 | ) 15 | 16 | target_compile_definitions(${PROJECT_NAME} PRIVATE 17 | APP_VERSION="${PROJECT_VERSION}" 18 | ) 19 | 20 | target_include_directories(${PROJECT_NAME} PRIVATE .) 21 | 22 | if (WIN32) 23 | include(${PROJECT_CMAKE_MODULES_DIR}/winrc.cmake) 24 | 25 | if (NOT ${CMAKE_BUILD_TYPE} MATCHES "Deb") 26 | set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE) 27 | endif () 28 | endif () 29 | 30 | if (APPLE) 31 | set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE) 32 | endif () 33 | 34 | set_property(TARGET DeployedTargets APPEND PROPERTY TARGETS ${PROJECT_NAME}) -------------------------------------------------------------------------------- /src/apps/SlurCutter/gui/DsSentence.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | struct DsSentence { 12 | QString text; 13 | QString ph_seq; 14 | QString ph_dur; 15 | QString ph_num; 16 | QString note_seq; 17 | QString note_dur; 18 | QString note_slur; 19 | QString f0_seq; 20 | QString f0_timestep; 21 | QString note_glide; 22 | 23 | DsSentence() = default; 24 | DsSentence(QString text, QString ph_seq, QString ph_dur, QString ph_num, QString note_seq, QString note_dur, 25 | QString note_slur, QString f0_seq, QString f0_timestep, QString note_glide); 26 | }; 27 | 28 | inline DsSentence::DsSentence(QString text, QString ph_seq, QString ph_dur, QString ph_num, QString note_seq, 29 | QString note_dur, QString note_slur, QString f0_seq, QString f0_timestep, 30 | QString note_glide) 31 | : text(std::move(text)), ph_seq(std::move(ph_seq)), ph_dur(std::move(ph_dur)), ph_num(std::move(ph_num)), 32 | note_seq(std::move(note_seq)), note_dur(std::move(note_dur)), note_slur(std::move(note_slur)), 33 | f0_seq(std::move(f0_seq)), f0_timestep(std::move(f0_timestep)), note_glide(std::move(note_glide)) { 34 | } 35 | 36 | inline DsSentence loadDsSentencesFromJsonObj(const QJsonObject &content, QString *error = nullptr) { 37 | DsSentence sentence; 38 | sentence.text = content.value("text").toString(); 39 | sentence.ph_seq = content.value("ph_seq").toString(); 40 | sentence.ph_dur = content.value("ph_dur").toString(); 41 | sentence.ph_num = content.value("ph_num").toString(); 42 | sentence.note_seq = content.value("note_seq").toString(); 43 | sentence.note_dur = content.value("note_dur").toString(); 44 | sentence.note_slur = content.value("note_slur").toString(); 45 | sentence.f0_seq = content.value("f0_seq").toString(); 46 | sentence.f0_timestep = content.value("f0_timestep").toString(); 47 | sentence.note_glide = content.value("note_glide").toString(); 48 | 49 | return sentence; 50 | } 51 | -------------------------------------------------------------------------------- /src/apps/SlurCutter/gui/MainWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "F0Widget.h" 19 | #include "PlayWidget.h" 20 | 21 | #include "Api/IAudioDecoder.h" 22 | #include "Api/IAudioPlayback.h" 23 | 24 | #include 25 | 26 | class MainWindow : public QMainWindow { 27 | Q_OBJECT 28 | public: 29 | MainWindow(QWidget *parent = nullptr); 30 | ~MainWindow(); 31 | 32 | protected: 33 | QMenu *fileMenu; 34 | QAction *browseAction; 35 | 36 | QMenu *editMenu; 37 | QAction *nextAction; 38 | QAction *prevAction; 39 | 40 | QMenu *playMenu; 41 | QAction *playAction; 42 | 43 | QMenu *helpMenu; 44 | QAction *aboutAppAction; 45 | QAction *aboutQtAction; 46 | 47 | int notifyTimerId; 48 | bool playing; 49 | QString dirname; 50 | 51 | PlayWidget *playerWidget; 52 | F0Widget *f0Widget; 53 | 54 | QTreeView *treeView; 55 | QFileSystemModel *fsModel; 56 | QListWidget *sentenceWidget; 57 | 58 | QSplitter *mainSplitter; 59 | QSplitter *fsSentencesSplitter; 60 | 61 | QVBoxLayout *rightLayout; 62 | QWidget *rightWidget; 63 | 64 | QString lastFile; 65 | bool fileSwitchDirection = true; // true = next, false = prev 66 | 67 | // Cached DS file content 68 | // We only store DS's first layer of objects, anything else is parsed on the fly 69 | QVector dsContent; 70 | int currentRow = -1; 71 | 72 | // Cached application configuration 73 | QSettings cfg; 74 | 75 | void openDirectory(const QString &dirname); 76 | void openFile(const QString &filename); 77 | bool saveFile(const QString &filename); 78 | 79 | void pullEditedMidi(); 80 | void switchFile(bool next); 81 | void switchSentence(bool next); 82 | 83 | void loadDsContent(const QString &content); 84 | Q_SLOT void reloadDsSentenceRequested(); 85 | 86 | void reloadWindowTitle(); 87 | 88 | void dragEnterEvent(QDragEnterEvent *event) override; 89 | void dropEvent(QDropEvent *event) override; 90 | void closeEvent(QCloseEvent *event) override; 91 | 92 | private: 93 | void initStyleSheet(); 94 | void applyConfig(); 95 | 96 | void _q_fileMenuTriggered(const QAction *action); 97 | void _q_editMenuTriggered(QAction *action); 98 | void _q_playMenuTriggered(QAction *action); 99 | void _q_helpMenuTriggered(const QAction *action); 100 | void _q_treeCurrentChanged(const QModelIndex ¤t, const QModelIndex &previous); 101 | void _q_sentenceChanged(int currentRow); 102 | }; 103 | 104 | #endif // MAINWINDOW_H 105 | -------------------------------------------------------------------------------- /src/apps/SlurCutter/gui/PlayWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef PLAYWIDGET_H 2 | #define PLAYWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "Api/IAudioDecoder.h" 17 | #include "Api/IAudioPlayback.h" 18 | 19 | #include "Api/interfaces/IAudioDecoderPlugin.h" 20 | #include "Api/interfaces/IAudioPlaybackPlugin.h" 21 | 22 | class PlayWidget : public QWidget { 23 | Q_OBJECT 24 | public: 25 | PlayWidget(QWidget *parent = nullptr); 26 | ~PlayWidget(); 27 | 28 | void openFile(const QString &filename); 29 | 30 | bool isPlaying() const; 31 | void setPlaying(bool playing); 32 | 33 | void setRange(double start, double end); 34 | 35 | signals: 36 | void playheadChanged(double position); 37 | 38 | protected: 39 | // QPluginLoader decoderLoader, playbackLoader; 40 | 41 | // QsApi::IAudioDecoderPlugin *decoder_plugin; 42 | // QsApi::IAudioPlaybackPlugin *playback_plugin; 43 | QsApi::IAudioDecoder *decoder; 44 | QsApi::IAudioPlayback *playback; 45 | 46 | QMenu *deviceMenu; 47 | QActionGroup *deviceActionGroup; 48 | 49 | int notifyTimerId; 50 | bool playing; 51 | QString filename; 52 | 53 | QLabel *fileLabel; 54 | QSlider *slider; 55 | QLabel *timeLabel; 56 | 57 | QPushButton *playButton; 58 | QPushButton *stopButton; 59 | QPushButton *devButton; 60 | 61 | QVBoxLayout *mainLayout; 62 | QHBoxLayout *buttonsLayout; 63 | 64 | 65 | // Manually maintained time 66 | uint64_t lastObtainedTimeMs = 0, pauseAtTime = 0; 67 | std::chrono::time_point lastObtainedTimePoint; 68 | uint64_t estimatedTimeMs(); 69 | 70 | // Limited time range 71 | double rangeBegin = 0.0, rangeEnd = 0.0; 72 | 73 | void timerEvent(QTimerEvent *event) override; 74 | 75 | private: 76 | void initPlugins(); 77 | void uninitPlugins(); 78 | 79 | void reloadDevices(); 80 | void reloadButtonStatus(); 81 | void reloadSliderStatus(); 82 | void reloadDeviceActionStatus(); 83 | void reloadFinePlayheadStatus(uint64_t timeMs = UINT64_MAX); 84 | 85 | void _q_playButtonClicked(); 86 | void _q_stopButtonClicked(); 87 | void _q_devButtonClicked(); 88 | void _q_sliderReleased(); 89 | void _q_deviceActionTriggered(const QAction *action); 90 | void _q_playStateChanged(); 91 | void _q_audioDeviceChanged(); 92 | void _q_audioDeviceAdded(); 93 | void _q_audioDeviceRemoved(); 94 | }; 95 | 96 | #endif // PLAYWIDGET_H 97 | -------------------------------------------------------------------------------- /src/apps/SlurCutter/main.cpp: -------------------------------------------------------------------------------- 1 | #include "gui/MainWindow.h" 2 | 3 | #include 4 | 5 | #ifdef Q_OS_WINDOWS 6 | # include 7 | # include 8 | #endif 9 | 10 | bool isUserRoot() { 11 | #ifdef Q_OS_WINDOWS 12 | return IsUserAnAdmin(); 13 | #else 14 | return geteuid() == 0; 15 | #endif 16 | } 17 | 18 | int main(int argc, char *argv[]) { 19 | // QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 20 | // QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); 21 | QApplication a(argc, argv); 22 | 23 | if (isUserRoot() && !a.arguments().contains("--allow-root")) { 24 | QString title = qApp->applicationName(); 25 | QString msg = QString("You're trying to start %1 as the %2, which may cause " 26 | "security problem and isn't recommended.") 27 | .arg(qApp->applicationName(), "Administrator"); 28 | #ifdef Q_OS_WINDOWS 29 | MessageBoxW(0, msg.toStdWString().data(), title.toStdWString().data(), 30 | MB_OK | MB_TOPMOST | MB_SETFOREGROUND | MB_ICONWARNING); 31 | #elif defined(Q_OS_LINUX) 32 | fputs(qPrintable(msg), stdout); 33 | #else 34 | QMessageBox::warning(nullptr, title, msg, QApplication::tr("Confirm")); 35 | #endif 36 | return 0; 37 | } 38 | 39 | #ifdef Q_OS_WINDOWS 40 | QFont f("Microsoft YaHei"); 41 | f.setPointSize(9); 42 | a.setFont(f); 43 | #endif 44 | 45 | // Set library loading info 46 | // #ifdef Q_OS_MAC 47 | // qApp->addLibraryPath(qApp->applicationDirPath() + "/../Frameworks/ChorusKit/plugins"); 48 | // #else 49 | // qApp->addLibraryPath(qApp->applicationDirPath() + "/../lib/ChorusKit/plugins"); 50 | // #endif 51 | 52 | MainWindow w; 53 | w.show(); 54 | 55 | return a.exec(); 56 | } 57 | -------------------------------------------------------------------------------- /src/apps/SlurCutter/res.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | res/pause.svg 4 | res/play.svg 5 | res/stop.svg 6 | res/app.qss 7 | res/audio.svg 8 | res/clipboard.svg 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/apps/SlurCutter/res/app.qss: -------------------------------------------------------------------------------- 1 | QSlider:horizontal { 2 | height: 30px; 3 | } 4 | QSlider::groove:horizontal { 5 | height: 20px; 6 | background: #005A9E; 7 | } 8 | 9 | QSlider::groove:vertical { 10 | width: 5px; 11 | background: #005A9E; 12 | } 13 | 14 | QSlider::handle:horizontal { 15 | background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1, stop: 0 #b4b4b4, stop: 1 #8f8f8f); 16 | border: 1px solid #5c5c5c; 17 | width: 15px; 18 | margin: -5px 0; 19 | /* border-radius: 10px; */ 20 | } 21 | 22 | QSlider::handle:vertical { 23 | background: qlineargradient(x1: 1, y1: 1, x2: 0, y2: 0, stop: 0 #b4b4b4, stop: 1 #8f8f8f); 24 | border: 1px solid #5c5c5c; 25 | height: 14px; 26 | margin: 0 -5px; 27 | border-radius: 7px; 28 | } 29 | 30 | QSlider::add-page:horizontal { 31 | background: #868686; 32 | } 33 | 34 | QSlider::add-page:vertical { 35 | background: #868686; 36 | } 37 | 38 | QSlider::sub-page:horizontal { 39 | background: #005A9E; 40 | } 41 | 42 | QSlider::sub-page:vertical { 43 | background: #005A9E; 44 | } 45 | 46 | QPushButton[type=user] { 47 | padding: 5px; 48 | } 49 | 50 | QLineEdit { 51 | padding: 5px; 52 | } 53 | 54 | QPlainTextEdit { 55 | background-color: white; 56 | padding: 5px; 57 | } -------------------------------------------------------------------------------- /src/apps/SlurCutter/res/audio.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/apps/SlurCutter/res/clipboard.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/apps/SlurCutter/res/pause.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/apps/SlurCutter/res/play.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/apps/SlurCutter/res/stop.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/apps/SomeInfer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(SomeInfer VERSION 0.0.0.1) 2 | 3 | set(CMAKE_AUTOMOC ON) 4 | set(CMAKE_AUTORCC ON) 5 | set(CMAKE_AUTOUIC ON) 6 | 7 | file(GLOB_RECURSE _src *.h *.cpp) 8 | add_executable(${PROJECT_NAME} ${_src}) 9 | 10 | find_package(SndFile CONFIG REQUIRED) 11 | target_link_libraries(${PROJECT_NAME} PRIVATE 12 | Qt${QT_VERSION_MAJOR}::Core 13 | Qt${QT_VERSION_MAJOR}::Widgets 14 | some-infer::some-infer 15 | ) 16 | 17 | target_compile_definitions(${PROJECT_NAME} PRIVATE 18 | APP_VERSION="${PROJECT_VERSION}" 19 | ) 20 | 21 | target_include_directories(${PROJECT_NAME} PRIVATE .) 22 | 23 | 24 | if (WIN32) 25 | include(${PROJECT_CMAKE_MODULES_DIR}/winrc.cmake) 26 | 27 | if (NOT ${CMAKE_BUILD_TYPE} MATCHES "Deb") 28 | set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE) 29 | endif () 30 | 31 | if ("$ENV{WindowsSDKVersion}" MATCHES [[^([0-9.]*)(\\|/)?$]]) 32 | set(WINDOWS_SDK_VERSION "${CMAKE_MATCH_1}") 33 | else () 34 | message(WARNING "Failed to parse Windows SDK version from ENV{WindowsSDKVersion}.") 35 | endif () 36 | 37 | set(WINDOWS_SDK_DIR "$ENV{WindowsSdkDir}") 38 | 39 | if (WINDOWS_SDK_DIR AND WINDOWS_SDK_VERSION) 40 | include_directories("${WINDOWS_SDK_DIR}Include/${WINDOWS_SDK_VERSION}/um") 41 | link_directories("${WINDOWS_SDK_DIR}Lib/${WINDOWS_SDK_VERSION}/um/x64") 42 | 43 | target_link_libraries(${PROJECT_NAME} PRIVATE dxgi) 44 | else () 45 | message(WARNING "Windows SDK not found. Please ensure Windows SDK is installed.") 46 | endif () 47 | endif () 48 | 49 | if (APPLE) 50 | set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE) 51 | endif () 52 | 53 | set_property(TARGET DeployedTargets APPEND PROPERTY TARGETS ${PROJECT_NAME}) -------------------------------------------------------------------------------- /src/apps/SomeInfer/gui/BatchWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef BATCHWIDGET_H 2 | #define BATCHWIDGET_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | 12 | 13 | class QPushButton; 14 | class QLineEdit; 15 | 16 | class BatchWidget final : public QWidget { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit BatchWidget(std::shared_ptr some, QSettings *cfg, QWidget *parent = nullptr); 21 | 22 | QLineEdit *m_wavPathLineEdit; 23 | QLineEdit *m_csvLineEdit; 24 | 25 | private slots: 26 | void onBrowseWavPath(); 27 | void onBrowseOutputCsv(); 28 | 29 | void onExportMidiTask() const; 30 | 31 | private: 32 | QSettings *m_cfg; 33 | std::shared_ptr m_some; 34 | QPushButton *m_wavPathButton; 35 | QPushButton *m_csvButton; 36 | 37 | QProgressBar *m_progressBar; 38 | QPushButton *m_runButton; 39 | }; 40 | 41 | #endif // BATCHWIDGET_H 42 | -------------------------------------------------------------------------------- /src/apps/SomeInfer/gui/MainWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "MidiWidget.h" 11 | 12 | class MainWindow final : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow() override; 18 | 19 | private: 20 | void applyConfig(); 21 | 22 | QHBoxLayout *mainLayout; 23 | QTabWidget *parentWidget; 24 | MidiWidget *midiWidget; 25 | 26 | QSettings *cfg; 27 | 28 | std::shared_ptr m_some; 29 | }; 30 | 31 | #endif // MAINWINDOW_H 32 | -------------------------------------------------------------------------------- /src/apps/SomeInfer/gui/MidiWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MIDIWIDGET_H 2 | #define MIDIWIDGET_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | 12 | class QLineEdit; 13 | class QPushButton; 14 | 15 | class MidiWidget final : public QWidget { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit MidiWidget(std::shared_ptr some, QSettings *cfg, QWidget *parent = nullptr); 20 | 21 | QLineEdit *m_wavPathLineEdit; 22 | QLineEdit *m_tempoLineEdit; 23 | QLineEdit *m_outputMidiLineEdit; 24 | 25 | private slots: 26 | void onBrowseWavPath(); 27 | void onBrowseOutputMidi(); 28 | 29 | void onExportMidiTask() const; 30 | 31 | private: 32 | QSettings *m_cfg; 33 | std::shared_ptr m_some; 34 | QPushButton *m_wavPathButton; 35 | QPushButton *m_outputMidiButton; 36 | 37 | QProgressBar *m_progressBar; 38 | QPushButton *m_runButton; 39 | }; 40 | 41 | #endif // MIDIWIDGET_H -------------------------------------------------------------------------------- /src/apps/SomeInfer/main.cpp: -------------------------------------------------------------------------------- 1 | #include "gui/MainWindow.h" 2 | 3 | #include 4 | 5 | int main(int argc, char* argv[]) { 6 | QApplication a(argc, argv); 7 | 8 | MainWindow w; 9 | w.show(); 10 | 11 | return QApplication::exec(); 12 | } 13 | -------------------------------------------------------------------------------- /src/apps/SomeInfer/utils/DmlGpuUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by fluty on 24-9-28. 3 | // 4 | 5 | #ifndef DMLGPUUTILS_H 6 | #define DMLGPUUTILS_H 7 | 8 | #include "GpuInfo.h" 9 | 10 | #include 11 | 12 | class DmlGpuUtils { 13 | public: 14 | static GpuInfo getGpuByIndex(int adapterIndex); 15 | static QList getGpuList(); 16 | static GpuInfo getGpuByPciDeviceVendorId(unsigned int pciDeviceId, unsigned int pciVendorId, int indexHint = 0); 17 | static GpuInfo getGpuByPciDeviceVendorIdString(const QString &idString, int indexHint = 0); 18 | static GpuInfo getRecommendedGpu(); 19 | }; 20 | 21 | #ifndef _WIN32 22 | inline GpuInfo DmlGpuUtils::getGpuByIndex(int index) { 23 | Q_UNUSED(index) 24 | return {}; 25 | } 26 | 27 | inline QList DmlGpuUtils::getGpuList() { 28 | return {}; 29 | } 30 | 31 | inline GpuInfo DmlGpuUtils::getGpuByPciDeviceVendorId(unsigned int pciDeviceId, unsigned int pciVendorId, int indexHint) { 32 | Q_UNUSED(pciDeviceId) 33 | Q_UNUSED(pciVendorId) 34 | Q_UNUSED(indexHint) 35 | return {}; 36 | } 37 | 38 | inline GpuInfo DmlGpuUtils::getGpuByPciDeviceVendorIdString(const QString &idString, int indexHint) { 39 | Q_UNUSED(idString) 40 | Q_UNUSED(indexHint) 41 | return {}; 42 | } 43 | 44 | inline GpuInfo DmlGpuUtils::getRecommendedGpu() { 45 | return {}; 46 | } 47 | #endif 48 | 49 | #endif // DMLGPUUTILS_H 50 | -------------------------------------------------------------------------------- /src/apps/SomeInfer/utils/GpuInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by fluty on 24-9-28. 3 | // 4 | 5 | #ifndef GPUINFO_H 6 | #define GPUINFO_H 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | class GpuInfo { 13 | public: 14 | int index = -1; 15 | QString description; 16 | QString deviceId; 17 | unsigned long long memory = 0; 18 | 19 | static inline QString getIdString(unsigned int device_id, unsigned int vendor_id); 20 | static inline bool parseIdString(QStringView idString, unsigned int &device_id, unsigned int &vendor_id); 21 | 22 | }; 23 | 24 | 25 | inline QString GpuInfo::getIdString(unsigned int device_id, unsigned int vendor_id) { 26 | constexpr int ID_STR_LEN = 8; 27 | char s[ID_STR_LEN + 1] = { '\0' }; 28 | snprintf(s, sizeof(s), "%04X%04X", device_id, vendor_id); 29 | return QString::fromLatin1(s, ID_STR_LEN); 30 | } 31 | 32 | inline bool GpuInfo::parseIdString(QStringView idString, unsigned int &device_id, unsigned int &vendor_id) { 33 | // Guaranteed: If the function returns false, both device_id and vendor_id are not modified. 34 | 35 | QStringView::size_type pos = 0; 36 | 37 | if (idString.startsWith(QStringLiteral("0x"), Qt::CaseInsensitive)) { 38 | pos += 2; 39 | } 40 | 41 | if (idString.length() - pos < 8) { 42 | return false; 43 | } 44 | 45 | unsigned int out_device_id, out_vendor_id; 46 | bool ok; 47 | 48 | if (out_device_id = idString.mid(pos, 4).toUInt(&ok, 16); !ok) { 49 | return false; 50 | } 51 | if (out_vendor_id = idString.mid(pos + 4, 4).toUInt(&ok, 16); !ok) { 52 | return false; 53 | } 54 | device_id = out_device_id; 55 | vendor_id = out_vendor_id; 56 | 57 | return true; 58 | } 59 | 60 | Q_DECLARE_METATYPE(GpuInfo) 61 | 62 | #endif //GPUINFO_H 63 | -------------------------------------------------------------------------------- /src/libs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(qsmedia) 2 | 3 | add_subdirectory(ffmpegdecoder) 4 | 5 | add_subdirectory(sdlplayback) 6 | 7 | add_subdirectory(FunAsr) 8 | 9 | add_subdirectory(audio-util) 10 | 11 | add_subdirectory(some-infer) 12 | 13 | add_subdirectory(rmvpe-infer) -------------------------------------------------------------------------------- /src/libs/FunAsr/Acknowledge.md: -------------------------------------------------------------------------------- 1 | ## Acknowledge 2 | 3 | 1. We borrowed a lot of code from [Kaldi](http://kaldi-asr.org/) for data preparation. 4 | 2. We borrowed a lot of code from [ESPnet](https://github.com/espnet/espnet). FunASR follows up the training and finetuning pipelines of ESPnet. 5 | 3. We referred [Wenet](https://github.com/wenet-e2e/wenet) for building dataloader for large scale data training. 6 | 4. We acknowledge [ChinaTelecom](https://github.com/zhuzizyf/damo-fsmn-vad-infer-httpserver) for contributing the VAD runtime. 7 | 5. We acknowledge [RapidAI](https://github.com/RapidAI) for contributing the Paraformer and CT_Transformer-punc runtime. 8 | 6. We acknowledge [AiHealthx](http://www.aihealthx.com/) for contributing the websocket service and html5. 9 | 7. We acknowledge [XVERSE](http://www.xverse.cn/index.html) for contributing the grpc service. 10 | 8. We acknowledge [blt](https://github.com/bltcn) for develop and deploy website. -------------------------------------------------------------------------------- /src/libs/FunAsr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(FunAsr) 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(CMAKE_CXX_STANDARD 17) 5 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 6 | 7 | add_subdirectory(src) -------------------------------------------------------------------------------- /src/libs/FunAsr/include/Audio.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_H 2 | #define AUDIO_H 3 | 4 | #include 5 | #include 6 | 7 | namespace FunAsr { 8 | class AudioFrame { 9 | public: 10 | explicit AudioFrame(const int &len); 11 | ~AudioFrame(); 12 | int get_start() const; 13 | int get_len() const; 14 | 15 | private: 16 | int start; 17 | int len; 18 | }; 19 | 20 | class Audio { 21 | public: 22 | explicit Audio(const int &data_type); 23 | Audio(const int &data_type, const int &size); 24 | ~Audio(); 25 | bool loadwav(const char *buf, const int &nFileLen); 26 | bool loadPcmFloat(const float *buf, int num_samples); 27 | int fetch(float *&dout, int &len, int &flag); 28 | 29 | private: 30 | float *speech_data; 31 | int16_t *speech_buff; 32 | int speech_len; 33 | int speech_align_len; 34 | int offset; 35 | float align_size; 36 | int data_type; 37 | std::queue frame_queue; 38 | }; 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /src/libs/FunAsr/include/ComDefine.h: -------------------------------------------------------------------------------- 1 | #ifndef COMDEFINE_H 2 | #define COMDEFINE_H 3 | 4 | namespace FunAsr { 5 | #define S_BEGIN 0 6 | #define S_MIDDLE 1 7 | #define S_END 2 8 | #define S_ALL 3 9 | #define S_ERR 4 10 | } 11 | #endif 12 | -------------------------------------------------------------------------------- /src/libs/FunAsr/include/Model.h: -------------------------------------------------------------------------------- 1 | #ifndef MODEL_H 2 | #define MODEL_H 3 | 4 | #include 5 | #include 6 | 7 | namespace FunAsr { 8 | class Model { 9 | public: 10 | virtual ~Model() = default; 11 | virtual void reset() = 0; 12 | virtual std::string forward(float *din, int len, int flag) = 0; 13 | }; 14 | 15 | Model *create_model(const std::filesystem::path &path, const int &nThread = 0); 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /src/libs/FunAsr/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE _src *.h *.cpp) 2 | 3 | add_library(${PROJECT_NAME} ${_src}) 4 | target_include_directories(${PROJECT_NAME} PUBLIC *.h) 5 | 6 | find_package(fftw3 CONFIG REQUIRED) 7 | target_include_directories(${PROJECT_NAME} PUBLIC ${FFTW3_INCLUDE_DIRS}) 8 | target_link_directories(${PROJECT_NAME} PUBLIC ${FFTW3_LIBRARY_DIRS}) 9 | target_link_libraries(${PROJECT_NAME} PUBLIC fftw3 fftw3f) 10 | 11 | include_directories(../include) 12 | target_include_directories(${PROJECT_NAME} PUBLIC ../../onnxruntime/include) 13 | target_link_directories(${PROJECT_NAME} PUBLIC ../../onnxruntime/lib) 14 | 15 | if (WIN32) 16 | target_compile_definitions(${PROJECT_NAME} PUBLIC -D_RPASR_API_EXPORT) 17 | else () 18 | set(EXTRA_LIBS pthread) 19 | target_include_directories(${PROJECT_NAME} PUBLIC "/usr/local/opt/fftw/include") 20 | target_link_directories(${PROJECT_NAME} PUBLIC "/usr/local/opt/fftw/lib") 21 | 22 | target_include_directories(${PROJECT_NAME} PUBLIC "/usr/local/opt/openblas/include") 23 | target_link_directories(${PROJECT_NAME} PUBLIC "/usr/local/opt/openblas/lib") 24 | 25 | target_include_directories(${PROJECT_NAME} PUBLIC "/usr/include") 26 | target_link_directories(${PROJECT_NAME} PUBLIC "/usr/lib64") 27 | include_directories(${ONNXRUNTIME_DIR}/include) 28 | endif () 29 | 30 | target_include_directories(${PROJECT_NAME} PUBLIC ../include) 31 | target_link_libraries(${PROJECT_NAME} PUBLIC onnxruntime ${EXTRA_LIBS}) 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/libs/FunAsr/src/FeatureExtract.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FEATUREEXTRACT_H 3 | #define FEATUREEXTRACT_H 4 | 5 | #include 6 | 7 | #include "FeatureQueue.h" 8 | #include "SpeechWrap.h" 9 | #include "Tensor.h" 10 | 11 | namespace FunAsr { 12 | class FeatureExtract { 13 | private: 14 | SpeechWrap speech; 15 | FeatureQueue fqueue; 16 | int mode; 17 | 18 | float *fft_input{}; 19 | fftwf_complex *fft_out{}; 20 | fftwf_plan p{}; 21 | 22 | void fftw_init(); 23 | void melspect(const float *din, float *dout); 24 | void global_cmvn(float *din) const; 25 | 26 | public: 27 | explicit FeatureExtract(const int &mode); 28 | ~FeatureExtract(); 29 | int size() const; 30 | void reset(); 31 | void insert(float *din, int len, int flag); 32 | bool fetch(Tensor *&dout); 33 | }; 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /src/libs/FunAsr/src/FeatureQueue.cpp: -------------------------------------------------------------------------------- 1 | #include "FeatureQueue.h" 2 | 3 | #include 4 | 5 | namespace FunAsr { 6 | FeatureQueue::FeatureQueue() { 7 | buff = new Tensor(67, 80); 8 | window_size = 67; 9 | buff_idx = 0; 10 | } 11 | 12 | FeatureQueue::~FeatureQueue() { 13 | delete buff; 14 | } 15 | 16 | void FeatureQueue::reinit(const int &size) { 17 | delete buff; 18 | buff = new Tensor(size, 80); 19 | buff_idx = 0; 20 | window_size = size; 21 | } 22 | 23 | void FeatureQueue::reset() { 24 | buff_idx = 0; 25 | } 26 | 27 | void FeatureQueue::push(const float *din, const int &flag) { 28 | const int offset = buff_idx * 80; 29 | memcpy(buff->buff + offset, din, 80 * sizeof(float)); 30 | buff_idx++; 31 | 32 | if (flag == S_END) { 33 | auto *tmp = new Tensor(buff_idx, 80); 34 | memcpy(tmp->buff, buff->buff, buff_idx * 80 * sizeof(float)); 35 | feature_queue.push(tmp); 36 | buff_idx = 0; 37 | } else if (buff_idx == window_size) { 38 | feature_queue.push(buff); 39 | auto *tmp = new Tensor(window_size, 80); 40 | memcpy(tmp->buff, buff->buff + (window_size - 3) * 80, 3 * 80 * sizeof(float)); 41 | buff_idx = 3; 42 | buff = tmp; 43 | } 44 | } 45 | 46 | Tensor *FeatureQueue::pop() { 47 | Tensor *tmp = feature_queue.front(); 48 | feature_queue.pop(); 49 | return tmp; 50 | } 51 | 52 | int FeatureQueue::size() const { 53 | return static_cast(feature_queue.size()); 54 | } 55 | } -------------------------------------------------------------------------------- /src/libs/FunAsr/src/FeatureQueue.h: -------------------------------------------------------------------------------- 1 | #ifndef FEATUREQUEUE_H 2 | #define FEATUREQUEUE_H 3 | 4 | #include "Tensor.h" 5 | #include 6 | 7 | namespace FunAsr { 8 | class FeatureQueue { 9 | private: 10 | std::queue *> feature_queue; 11 | Tensor *buff; 12 | int buff_idx; 13 | int window_size; 14 | 15 | public: 16 | FeatureQueue(); 17 | ~FeatureQueue(); 18 | void reinit(const int &size); 19 | void reset(); 20 | void push(const float *din, const int &flag); 21 | Tensor *pop(); 22 | int size() const; 23 | }; 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /src/libs/FunAsr/src/Model.cpp: -------------------------------------------------------------------------------- 1 | #include "Model.h" 2 | 3 | #include "paraformer_onnx.h" 4 | 5 | #include 6 | 7 | namespace FunAsr { 8 | Model *create_model(const std::filesystem::path &path, const int &nThread) { 9 | return new ModelImp(path, nThread); 10 | } 11 | } -------------------------------------------------------------------------------- /src/libs/FunAsr/src/SpeechWrap.cpp: -------------------------------------------------------------------------------- 1 | #include "SpeechWrap.h" 2 | 3 | #include 4 | 5 | namespace FunAsr { 6 | SpeechWrap::SpeechWrap() { 7 | cache_size = 0; 8 | } 9 | 10 | SpeechWrap::~SpeechWrap() { 11 | } 12 | 13 | void SpeechWrap::reset() { 14 | cache_size = 0; 15 | } 16 | 17 | void SpeechWrap::load(float *din, int len) { 18 | in = din; 19 | in_size = len; 20 | total_size = cache_size + in_size; 21 | } 22 | 23 | int SpeechWrap::size() { 24 | return total_size; 25 | } 26 | 27 | void SpeechWrap::update(int offset) { 28 | int in_offset = offset - cache_size; 29 | cache_size = (total_size - offset); 30 | memcpy(cache, in + in_offset, cache_size * sizeof(float)); 31 | } 32 | 33 | float &SpeechWrap::operator[](int i) { 34 | return i < cache_size ? cache[i] : in[i - cache_size]; 35 | } 36 | } -------------------------------------------------------------------------------- /src/libs/FunAsr/src/SpeechWrap.h: -------------------------------------------------------------------------------- 1 | #ifndef SPEECHWRAP_H 2 | #define SPEECHWRAP_H 3 | 4 | namespace FunAsr { 5 | class SpeechWrap { 6 | private: 7 | float cache[400]; 8 | int cache_size; 9 | float *in; 10 | int in_size; 11 | int total_size; 12 | int next_cache_size; 13 | 14 | public: 15 | SpeechWrap(); 16 | ~SpeechWrap(); 17 | void load(float *din, int len); 18 | void update(int offset); 19 | void reset(); 20 | int size(); 21 | float &operator[](int i); 22 | }; 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /src/libs/FunAsr/src/Tensor.h: -------------------------------------------------------------------------------- 1 | #ifndef TENSOR_H 2 | #define TENSOR_H 3 | 4 | #include 5 | 6 | #include "alignedmem.h" 7 | namespace FunAsr { 8 | template 9 | class Tensor { 10 | private: 11 | void alloc_buff(); 12 | void free_buff() const; 13 | int mem_size{}; 14 | 15 | public: 16 | T *buff; 17 | int size[4]{}; 18 | int buff_size{}; 19 | explicit Tensor(Tensor *in); 20 | explicit Tensor(const int &a); 21 | Tensor(const int &a, const int &b); 22 | Tensor(const int &a, const int &b, const int &c); 23 | Tensor(const int &a, const int &b, const int &c, const int &d); 24 | ~Tensor(); 25 | }; 26 | 27 | template 28 | Tensor::Tensor(const int &a) : size{1, 1, 1, a} { 29 | alloc_buff(); 30 | } 31 | 32 | template 33 | Tensor::Tensor(const int &a, const int &b) : size{1, 1, a, b} { 34 | alloc_buff(); 35 | } 36 | 37 | template 38 | Tensor::Tensor(const int &a, const int &b, const int &c) : size{1, a, b, c} { 39 | alloc_buff(); 40 | } 41 | 42 | template 43 | Tensor::Tensor(const int &a, const int &b, const int &c, const int &d) : size{a, b, c, d} { 44 | alloc_buff(); 45 | } 46 | 47 | template 48 | Tensor::Tensor(Tensor *in) { 49 | memcpy(size, in->size, 4 * sizeof(int)); 50 | alloc_buff(); 51 | memcpy(buff, in->buff, in->buff_size * sizeof(T)); 52 | } 53 | 54 | template 55 | Tensor::~Tensor() { 56 | free_buff(); 57 | } 58 | 59 | template 60 | void Tensor::alloc_buff() { 61 | buff_size = size[0] * size[1] * size[2] * size[3]; 62 | mem_size = buff_size; 63 | buff = static_cast(aligned_malloc(32, buff_size * sizeof(T))); 64 | } 65 | 66 | template 67 | void Tensor::free_buff() const { 68 | aligned_free(buff); 69 | } 70 | } 71 | #endif 72 | -------------------------------------------------------------------------------- /src/libs/FunAsr/src/Vocab.h: -------------------------------------------------------------------------------- 1 | #ifndef VOCAB_H 2 | #define VOCAB_H 3 | 4 | #include 5 | #include 6 | 7 | namespace FunAsr { 8 | class Vocab { 9 | private: 10 | std::vector vocab; 11 | static bool isChinese(const std::string &ch); 12 | 13 | public: 14 | explicit Vocab(const char *filename); 15 | #ifdef _WIN32 16 | explicit Vocab(const wchar_t *filename); 17 | #endif 18 | ~Vocab(); 19 | int size() const; 20 | std::string vector2stringV2(const std::vector &in) const; 21 | }; 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /src/libs/FunAsr/src/alignedmem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace FunAsr { 4 | void *aligned_malloc(size_t alignment, size_t required_bytes) { 5 | void *p1; // original block 6 | const int offset = alignment - 1 + sizeof(void *); 7 | if ((p1 = (void *) malloc(required_bytes + offset)) == nullptr) { 8 | return nullptr; 9 | } 10 | // aligned block 11 | auto **p2 = (void **) (((size_t) (p1) + offset) & ~(alignment - 1)); 12 | p2[-1] = p1; 13 | return p2; 14 | } 15 | 16 | void aligned_free(void *p) { 17 | free(((void **) p)[-1]); 18 | } 19 | } -------------------------------------------------------------------------------- /src/libs/FunAsr/src/alignedmem.h: -------------------------------------------------------------------------------- 1 | #ifndef ALIGNEDMEM_H 2 | #define ALIGNEDMEM_H 3 | namespace FunAsr { 4 | extern void *aligned_malloc(size_t alignment, size_t required_bytes); 5 | extern void aligned_free(void *p); 6 | } 7 | #endif 8 | -------------------------------------------------------------------------------- /src/libs/FunAsr/src/commonfunc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace FunAsr { 8 | typedef struct { 9 | std::string msg; 10 | float snippet_time; 11 | } RPASR_RECOG_RESULT; 12 | 13 | #ifdef _WIN32 14 | 15 | inline std::wstring string2wstring(const std::string &str, const std::string &locale) { 16 | typedef std::codecvt_byname F; 17 | std::wstring_convert strCnv(new F(locale)); 18 | return strCnv.from_bytes(str); 19 | } 20 | 21 | inline std::wstring strToWstr(const std::string &str) { 22 | if (str.empty()) 23 | return L""; 24 | return string2wstring(str, "zh-CN"); 25 | } 26 | 27 | #endif 28 | 29 | inline void getInputName(const Ort::Session *session, std::string &inputName, int nIndex = 0) { 30 | const size_t numInputNodes = session->GetInputCount(); 31 | if (numInputNodes > 0) { 32 | Ort::AllocatorWithDefaultOptions allocator; 33 | { 34 | const auto t = session->GetInputNameAllocated(nIndex, allocator); 35 | inputName = t.get(); 36 | } 37 | } 38 | } 39 | 40 | inline void getOutputName(const Ort::Session *session, std::string &outputName, int nIndex = 0) { 41 | const size_t numOutputNodes = session->GetOutputCount(); 42 | if (numOutputNodes > 0) { 43 | Ort::AllocatorWithDefaultOptions allocator; 44 | { 45 | const auto t = session->GetOutputNameAllocated(nIndex, allocator); 46 | outputName = t.get(); 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/libs/FunAsr/src/paraformer_onnx.h: -------------------------------------------------------------------------------- 1 | #ifndef PARAFORMER_MODELIMP_H 2 | #define PARAFORMER_MODELIMP_H 3 | #pragma once 4 | #include "FeatureExtract.h" 5 | 6 | #include 7 | #include 8 | 9 | #include "Vocab.h" 10 | 11 | namespace FunAsr { 12 | class ModelImp final : public Model { 13 | private: 14 | FeatureExtract *fe; 15 | 16 | Vocab *vocab; 17 | 18 | static void apply_lfr(Tensor *&din); 19 | static void apply_cmvn(const Tensor *din); 20 | 21 | std::string greedy_search(float *in, const int &nLen) const; 22 | 23 | #ifdef _WIN_X86 24 | Ort::MemoryInfo m_memoryInfo = Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU); 25 | #else 26 | Ort::MemoryInfo m_memoryInfo = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); 27 | #endif 28 | 29 | Ort::Session *m_session = nullptr; 30 | Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_ERROR, "paraformer"); 31 | Ort::SessionOptions sessionOptions = Ort::SessionOptions(); 32 | 33 | std::vector m_strInputNames, m_strOutputNames; 34 | std::vector m_szInputNames; 35 | std::vector m_szOutputNames; 36 | 37 | public: 38 | explicit ModelImp(const std::filesystem::path &, const int &nNumThread = 0); 39 | ~ModelImp() override; 40 | void reset() override; 41 | std::string forward(float *din, int len, int flag) override; 42 | }; 43 | 44 | } // namespace paraformer 45 | #endif 46 | -------------------------------------------------------------------------------- /src/libs/FunAsr/src/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | #include "Tensor.h" 5 | #include 6 | 7 | namespace FunAsr { 8 | extern float *loadparams(const char *filename); 9 | 10 | extern void SaveDataFile(const char *filename, void *data, uint32_t len); 11 | extern void relu(Tensor *din); 12 | extern void swish(Tensor *din); 13 | extern void sigmoid(Tensor *din); 14 | extern void doubleswish(Tensor *din); 15 | 16 | extern void softmax(float *din, int mask, int len); 17 | 18 | extern void log_softmax(float *din, int len); 19 | extern int val_align(int val, int align); 20 | extern void disp_params(float *din, int size); 21 | 22 | extern void basic_norm(Tensor *&din, float norm); 23 | 24 | extern void findmax(float *din, int len, float &max_val, int &max_idx); 25 | 26 | extern void glu(Tensor *din, Tensor *dout); 27 | 28 | std::string pathAppend(const std::string &p1, const std::string &p2); 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /src/libs/audio-util/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: LLVM 4 | AccessModifierOffset: -4 5 | AlignConsecutiveAssignments: false 6 | AlignConsecutiveDeclarations: false 7 | AlignOperands: false 8 | AlignTrailingComments: false 9 | AlwaysBreakTemplateDeclarations: Yes 10 | BraceWrapping: 11 | AfterCaseLabel: true 12 | AfterClass: false 13 | AfterControlStatement: false 14 | AfterEnum: false 15 | AfterFunction: false 16 | AfterNamespace: true 17 | AfterStruct: false 18 | AfterUnion: false 19 | AfterExternBlock: false 20 | BeforeCatch: true 21 | BeforeElse: false 22 | BeforeLambdaBody: true 23 | BeforeWhile: true 24 | SplitEmptyFunction: false 25 | SplitEmptyRecord: false 26 | SplitEmptyNamespace: false 27 | BreakBeforeBraces: Custom 28 | BreakConstructorInitializers: AfterColon 29 | BreakConstructorInitializersBeforeComma: false 30 | ColumnLimit: 120 31 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 32 | IncludeCategories: 33 | - Regex: '^<.*' 34 | Priority: 1 35 | - Regex: '^".*' 36 | Priority: 2 37 | - Regex: '.*' 38 | Priority: 3 39 | IncludeIsMainRegex: '([-_](test|unittest))?$' 40 | IndentCaseBlocks: true 41 | IndentWidth: 4 42 | InsertNewlineAtEOF: true 43 | MacroBlockBegin: '' 44 | MacroBlockEnd: '' 45 | MaxEmptyLinesToKeep: 2 46 | NamespaceIndentation: All 47 | SpaceInEmptyParentheses: false 48 | SpacesInAngles: false 49 | SpacesInConditionalStatement: false 50 | SpacesInCStyleCastParentheses: false 51 | SpacesInParentheses: false 52 | TabWidth: 4 53 | ... 54 | -------------------------------------------------------------------------------- /src/libs/audio-util/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | .DS_Store 35 | */.DS_Store 36 | 37 | build-src* 38 | build/ 39 | cmake-build* 40 | *.user 41 | *.lnk 42 | Libs/* 43 | _workingDir* 44 | .vscode 45 | .idea 46 | .cache 47 | cache 48 | .vs 49 | out/ 50 | CMakeSettings.json 51 | /vcpkg 52 | /data 53 | /*.natvis 54 | 55 | *.sublime-* 56 | setup-vcpkg.json 57 | setup-vcpkg-temp* -------------------------------------------------------------------------------- /src/libs/audio-util/audio-utilConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/audio-utilTargets.cmake") 4 | -------------------------------------------------------------------------------- /src/libs/audio-util/cmake/winrc.cmake: -------------------------------------------------------------------------------- 1 | set(_rc_content "#include 2 | 3 | #ifndef VS_VERSION_INFO 4 | #define VS_VERSION_INFO 1 5 | #endif 6 | 7 | #define _STRINGIFY(x) #x 8 | #define STRINGIFY(x) _STRINGIFY(x) 9 | 10 | VS_VERSION_INFO VERSIONINFO 11 | FILEVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},${PROJECT_VERSION_TWEAK} 12 | PRODUCTVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},${PROJECT_VERSION_TWEAK} 13 | { 14 | BLOCK \"StringFileInfo\" 15 | { 16 | // U.S. English - Windows, Multilingual 17 | BLOCK \"040904E4\" 18 | { 19 | VALUE \"FileDescription\", STRINGIFY(${RC_DESCRIPTION}) 20 | VALUE \"FileVersion\", STRINGIFY(${PROJECT_VERSION}) 21 | VALUE \"ProductName\", STRINGIFY(${PROJECT_NAME}) 22 | VALUE \"ProductVersion\", STRINGIFY(${PROJECT_VERSION}) 23 | VALUE \"LegalCopyright\", STRINGIFY(${RC_COPYRIGHT}) 24 | } 25 | } 26 | BLOCK \"VarFileInfo\" 27 | { 28 | VALUE \"Translation\", 0x409, 1252 // 1252 = 0x04E4 29 | } 30 | }") 31 | 32 | set(_rc_file ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_res.rc) 33 | file(WRITE ${_rc_file} ${_rc_content}) 34 | target_sources(${PROJECT_NAME} PRIVATE ${_rc_file}) -------------------------------------------------------------------------------- /src/libs/audio-util/include/audio-util/AudioUtilGlobal.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_UTIL_GLOBAL_H 2 | #define AUDIO_UTIL_GLOBAL_H 3 | 4 | #ifdef _MSC_VER 5 | # define AUDIO_UTIL_DECL_EXPORT __declspec(dllexport) 6 | # define AUDIO_UTIL_DECL_IMPORT __declspec(dllimport) 7 | #else 8 | # define AUDIO_UTIL_DECL_EXPORT __attribute__((visibility("default"))) 9 | # define AUDIO_UTIL_DECL_IMPORT __attribute__((visibility("default"))) 10 | #endif 11 | 12 | #ifndef AUDIO_UTIL_EXPORT 13 | # ifdef AUDIO_UTIL_STATIC 14 | # define AUDIO_UTIL_EXPORT 15 | # else 16 | # ifdef AUDIO_UTIL_LIBRARY 17 | # define AUDIO_UTIL_EXPORT AUDIO_UTIL_DECL_EXPORT 18 | # else 19 | # define AUDIO_UTIL_EXPORT AUDIO_UTIL_DECL_IMPORT 20 | # endif 21 | # endif 22 | #endif 23 | 24 | #endif //AUDIO_UTIL_GLOBAL_H 25 | -------------------------------------------------------------------------------- /src/libs/audio-util/include/audio-util/Slicer.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIOSLICER_H 2 | #define AUDIOSLICER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace AudioUtil 9 | { 10 | using MarkerList = std::vector>; 11 | 12 | class AUDIO_UTIL_EXPORT Slicer { 13 | public: 14 | Slicer(int sampleRate, float threshold, int hopSize, int winSize, int minLength, int minInterval, 15 | int maxSilKept); 16 | MarkerList slice(const std::vector &samples) const; 17 | 18 | private: 19 | int sample_rate; 20 | float threshold; 21 | int hop_size; 22 | int win_size; 23 | int min_length; 24 | int min_interval; 25 | int max_sil_kept; 26 | 27 | static std::vector get_rms(const std::vector &samples, int frame_length, int hop_length); 28 | }; 29 | } // namespace AudioUtil 30 | #endif // AUDIOSLICER_H 31 | -------------------------------------------------------------------------------- /src/libs/audio-util/include/audio-util/SndfileVio.h: -------------------------------------------------------------------------------- 1 | #ifndef SNDFILEVIO_H 2 | #define SNDFILEVIO_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace AudioUtil 10 | { 11 | sf_count_t AUDIO_UTIL_EXPORT qvio_get_filelen(void *user_data); 12 | sf_count_t AUDIO_UTIL_EXPORT qvio_seek(sf_count_t offset, int whence, void *user_data); 13 | sf_count_t AUDIO_UTIL_EXPORT qvio_read(void *ptr, sf_count_t count, void *user_data); 14 | sf_count_t AUDIO_UTIL_EXPORT qvio_write(const void *ptr, sf_count_t count, void *user_data); 15 | sf_count_t AUDIO_UTIL_EXPORT qvio_tell(void *user_data); 16 | 17 | struct AUDIO_UTIL_EXPORT QVIO { 18 | uint64_t seek{}; 19 | std::vector byteArray; 20 | }; 21 | 22 | struct AUDIO_UTIL_EXPORT SF_VIO { 23 | SF_VIRTUAL_IO vio{}; 24 | QVIO data; 25 | SF_INFO info; 26 | 27 | SF_VIO() { 28 | vio.get_filelen = qvio_get_filelen; 29 | vio.seek = qvio_seek; 30 | vio.read = qvio_read; 31 | vio.write = qvio_write; 32 | vio.tell = qvio_tell; 33 | } 34 | 35 | int size() const { return data.byteArray.size(); } 36 | const char *constData() const { return data.byteArray.data(); } 37 | }; 38 | } // namespace AudioUtil 39 | 40 | #endif // SNDFILEVIO_H 41 | -------------------------------------------------------------------------------- /src/libs/audio-util/include/audio-util/Util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace AudioUtil 9 | { 10 | SF_VIO AUDIO_UTIL_EXPORT resample_to_vio(const std::filesystem::path &filepath, std::string &msg, int tar_channel, 11 | int tar_samplerate); 12 | bool AUDIO_UTIL_EXPORT write_vio_to_wav(SF_VIO &sf_vio_in, const std::filesystem::path &filepath, 13 | int tar_channel = -1); 14 | } // namespace AudioUtil 15 | -------------------------------------------------------------------------------- /src/libs/audio-util/src/FlacDecoder.cpp: -------------------------------------------------------------------------------- 1 | #include "FlacDecoder.h" 2 | 3 | #include 4 | 5 | namespace AudioUtil 6 | { 7 | void write_flac_to_vio(const std::filesystem::path &filepath, SF_VIO &sf_vio) { 8 | SndfileHandle infile(filepath.string(), SFM_READ); 9 | if (!infile) { 10 | std::cerr << "Unable to open input file for reading: " << filepath << " Error: " << infile.strError() 11 | << std::endl; 12 | return; 13 | } 14 | 15 | const auto format = infile.format(); 16 | sf_vio.info.samplerate = infile.samplerate(); 17 | sf_vio.info.frames = infile.frames(); 18 | sf_vio.info.channels = infile.channels(); 19 | 20 | int bit_depth; 21 | if (format & SF_FORMAT_PCM_16) { 22 | bit_depth = 16; 23 | } else if (format & SF_FORMAT_PCM_24) { 24 | bit_depth = 24; 25 | } else if (format & SF_FORMAT_PCM_32) { 26 | bit_depth = 32; 27 | } else { 28 | std::cerr << "不支持的 FLAC 文件位深" << std::endl; 29 | return; 30 | } 31 | 32 | int output_format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; 33 | if (bit_depth == 24) { 34 | output_format = SF_FORMAT_WAV | SF_FORMAT_PCM_24; 35 | } else if (bit_depth == 32) { 36 | output_format = SF_FORMAT_WAV | SF_FORMAT_PCM_32; 37 | } 38 | 39 | sf_vio.info.format = output_format; 40 | 41 | SndfileHandle outfile(sf_vio.vio, &sf_vio.data, SFM_WRITE, output_format, sf_vio.info.channels, 42 | sf_vio.info.samplerate); 43 | if (!outfile) { 44 | std::cerr << "Unable to open output VIO for writing. Error message: " << outfile.strError() << std::endl; 45 | return; 46 | } 47 | 48 | const size_t estimated_size = sf_vio.info.frames * sf_vio.info.channels * sizeof(float); 49 | sf_vio.data.byteArray.reserve(estimated_size); 50 | 51 | constexpr int buffer_size = 1024; 52 | std::vector buffer(buffer_size * sf_vio.info.channels); 53 | 54 | int frames_read; 55 | while ((frames_read = infile.read(&buffer[0], buffer_size)) > 0) { 56 | if (outfile.write(&buffer[0], frames_read) != frames_read) { 57 | std::cerr << "Error writing data to VIO." << std::endl; 58 | return; 59 | } 60 | } 61 | 62 | std::cout << "Successfully wrote FLAC data to VIO." << std::endl; 63 | } 64 | 65 | } // namespace AudioUtil 66 | -------------------------------------------------------------------------------- /src/libs/audio-util/src/FlacDecoder.h: -------------------------------------------------------------------------------- 1 | #ifndef FLACDECODER_H 2 | #define FLACDECODER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace AudioUtil 9 | { 10 | void write_flac_to_vio(const std::filesystem::path &filepath, SF_VIO &sf_vio); 11 | } // namespace AudioUtil 12 | 13 | #endif // FLACDECODER_H 14 | -------------------------------------------------------------------------------- /src/libs/audio-util/src/MathUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef MATHUTILS_H 2 | #define MATHUTILS_H 3 | 4 | template 5 | inline T divIntRound(T n, T d); 6 | 7 | template 8 | inline T divIntRound(T n, T d) { 9 | /* 10 | * Integer division rounding to the closest integer, without converting to floating point numbers. 11 | */ 12 | // T should be an integer type (int, int64_t, qint64, ...) 13 | return ((n < 0) ^ (d < 0)) ? \ 14 | ((n - (d / 2)) / d) : \ 15 | ((n + (d / 2)) / d); 16 | } 17 | 18 | #endif // LYRICFA_MATHUTILS_H 19 | -------------------------------------------------------------------------------- /src/libs/audio-util/src/Mp3Decoder.h: -------------------------------------------------------------------------------- 1 | #ifndef MP3DECODER_H 2 | #define MP3DECODER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace AudioUtil 8 | { 9 | void write_mp3_to_vio(const std::filesystem::path &filepath, SF_VIO &sf_vio); 10 | } // namespace AudioUtil 11 | 12 | #endif // MP3DECODER_H 13 | -------------------------------------------------------------------------------- /src/libs/audio-util/src/SndfileVio.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace AudioUtil 6 | { 7 | sf_count_t qvio_get_filelen(void *user_data) { 8 | const auto *qvio = static_cast(user_data); 9 | return qvio->byteArray.size(); 10 | } 11 | 12 | sf_count_t qvio_seek(const sf_count_t offset, const int whence, void *user_data) { 13 | auto *qvio = static_cast(user_data); 14 | switch (whence) { 15 | case SEEK_SET: 16 | qvio->seek = offset; 17 | break; 18 | case SEEK_CUR: 19 | qvio->seek += offset; 20 | break; 21 | case SEEK_END: 22 | qvio->seek = qvio->byteArray.size() + offset; 23 | break; 24 | default: 25 | break; 26 | } 27 | return qvio->seek; 28 | } 29 | 30 | sf_count_t qvio_read(void *ptr, const sf_count_t count, void *user_data) { 31 | auto *qvio = static_cast(user_data); 32 | const sf_count_t remainingBytes = qvio->byteArray.size() - qvio->seek; 33 | const sf_count_t bytesToRead = std::min(count, remainingBytes); 34 | if (bytesToRead > 0) { 35 | std::memcpy(ptr, qvio->byteArray.data() + qvio->seek, bytesToRead); 36 | qvio->seek += bytesToRead; 37 | } 38 | return bytesToRead; 39 | } 40 | 41 | sf_count_t qvio_write(const void *ptr, const sf_count_t count, void *user_data) { 42 | auto *qvio = static_cast(user_data); 43 | auto *data = static_cast(ptr); 44 | qvio->byteArray.reserve(qvio->byteArray.size() + count); 45 | qvio->byteArray.insert(qvio->byteArray.end(), data, data + count); 46 | return count; 47 | } 48 | 49 | sf_count_t qvio_tell(void *user_data) { 50 | const auto *qvio = static_cast(user_data); 51 | return qvio->seek; 52 | } 53 | } // namespace Rmvpe 54 | -------------------------------------------------------------------------------- /src/libs/audio-util/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(TestAudioUtil) 2 | 3 | add_executable(${PROJECT_NAME} main.cpp) 4 | 5 | target_link_libraries(${PROJECT_NAME} PRIVATE 6 | audio-util::audio-util 7 | ) -------------------------------------------------------------------------------- /src/libs/audio-util/tests/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | int main(int argc, char *argv[]) { 10 | if (argc != 3) { 11 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 12 | return 1; 13 | } 14 | 15 | const std::filesystem::path audio_in_path = argv[1]; 16 | const std::filesystem::path wav_out_path = argv[2]; 17 | 18 | std::string errorMsg; 19 | auto sf_vio = AudioUtil::resample_to_vio(audio_in_path, errorMsg, 1, 16000); 20 | AudioUtil::write_vio_to_wav(sf_vio, wav_out_path, 1); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /src/libs/ffmpegdecoder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(FFmpegDecoder) 2 | 3 | set(CMAKE_AUTOMOC ON) 4 | set(CMAKE_AUTORCC ON) 5 | set(CMAKE_AUTOUIC ON) 6 | 7 | file(GLOB_RECURSE _src *.h *.cpp) 8 | 9 | add_library(${PROJECT_NAME} STATIC ${_src}) 10 | 11 | target_include_directories(${PROJECT_NAME} PUBLIC .) 12 | 13 | target_link_libraries(${PROJECT_NAME} PUBLIC 14 | QsMedia 15 | ) 16 | 17 | find_package(ffmpeg-fake REQUIRED NAMES FFmpeg) 18 | 19 | ffmpeg_link_libraries(${PROJECT_NAME} PRIVATE avcodec avformat avutil swresample) 20 | -------------------------------------------------------------------------------- /src/libs/ffmpegdecoder/FFmpegDecoder.h: -------------------------------------------------------------------------------- 1 | #ifndef FFMPEGDECODER_H 2 | #define FFMPEGDECODER_H 3 | 4 | #include "Api/IAudioDecoder.h" 5 | 6 | QSAPI_USING_NAMESPACE 7 | 8 | class FFmpegDecoderPrivate; 9 | 10 | class FFmpegDecoder final : public IAudioDecoder { 11 | Q_OBJECT 12 | Q_DECLARE_PRIVATE(FFmpegDecoder) 13 | public: 14 | explicit FFmpegDecoder(QObject *parent = nullptr); 15 | ~FFmpegDecoder() override; 16 | 17 | bool open(const QString &filename, const QsMedia::WaveArguments &args = {}) override; 18 | void close() override; 19 | 20 | bool isOpen() const override; 21 | 22 | NAudio::WaveFormat inFormat() const override; 23 | 24 | NAudio::WaveFormat Format() const override; 25 | 26 | void SetPosition(qint64 pos) override; 27 | 28 | qint64 Position() const override; 29 | qint64 Length() const override; 30 | 31 | int Read(char *buffer, int offset, int count) override; 32 | int Read(float *buffer, int offset, int count) override; 33 | 34 | protected: 35 | FFmpegDecoder(FFmpegDecoderPrivate &d, QObject *parent = nullptr); 36 | 37 | QScopedPointer d_ptr; 38 | }; 39 | 40 | 41 | #endif // FFMPEGDECODER_H 42 | -------------------------------------------------------------------------------- /src/libs/ffmpegdecoder/private/FFmpegDecoder_p.h: -------------------------------------------------------------------------------- 1 | #ifndef FFMPEGDECODERPRIVATE_H 2 | #define FFMPEGDECODERPRIVATE_H 3 | 4 | extern "C" { 5 | #include 6 | #include 7 | #include 8 | } 9 | 10 | #include "../FFmpegDecoder.h" 11 | 12 | #include 13 | #include 14 | 15 | class FFmpegDecoderPrivate { 16 | Q_DECLARE_PUBLIC(FFmpegDecoder); 17 | 18 | public: 19 | FFmpegDecoderPrivate(); 20 | ~FFmpegDecoderPrivate(); 21 | 22 | void init(); 23 | 24 | void clear(); 25 | 26 | bool initDecoder(); 27 | void quitDecoder(); 28 | 29 | int decode(char *buf, int size); 30 | void seek(); 31 | 32 | FFmpegDecoder *q_ptr; 33 | 34 | bool isOpen; 35 | 36 | struct WaveArguments { 37 | int SampleRate; 38 | AVSampleFormat SampleFormat; 39 | int Channels; 40 | 41 | WaveArguments() : WaveArguments(-1, AV_SAMPLE_FMT_NONE, -1) { 42 | } 43 | 44 | WaveArguments(AVSampleFormat fmt) : WaveArguments(-1, fmt, -1) { 45 | } 46 | 47 | WaveArguments(int sampleRate, AVSampleFormat fmt, int channels) { 48 | SampleRate = sampleRate; 49 | SampleFormat = fmt; 50 | Channels = channels; 51 | } 52 | 53 | int BytesPerSample() const { 54 | return av_get_bytes_per_sample(SampleFormat); 55 | } 56 | }; 57 | 58 | // FFmpeg 指针 59 | AVFormatContext *_formatContext; 60 | 61 | AVCodecContext *_codecContext; 62 | 63 | SwrContext *_swrContext; 64 | 65 | AVPacket *_packet; 66 | 67 | AVFrame *_frame; 68 | 69 | // 输入音频信息 70 | NAudio::WaveFormat _waveFormat; 71 | 72 | // 输出音频信息 73 | NAudio::WaveFormat _resampledFormat; 74 | 75 | // 文件名参数 76 | QString _fileName; 77 | 78 | // 输出参数 79 | WaveArguments _arguments; 80 | 81 | // 音频信息 82 | qint64 _length; // 单个声道总字节数 83 | 84 | qint64 _pos; // 单个声道已处理的字节数 85 | 86 | int _audioIndex; // 音频流序号 87 | 88 | AVChannelLayout _channelLayout; // 输出声道布局 89 | 90 | // 类内数据结构 91 | std::vector _cachedBuffer; // 内部缓冲区 92 | 93 | int _cachedBufferPos; // 内部缓冲区读取位置 94 | 95 | int _remainSamples; // 重采样器余量 96 | 97 | std::mutex lockObject; 98 | 99 | int orgBytesPerSample() const; 100 | 101 | qint64 src2dest_bytes(qint64 bytes) const; 102 | 103 | qint64 dest2src_bytes(qint64 bytes) const; 104 | 105 | static void error_on_channel_copy(int code); 106 | }; 107 | 108 | #endif // FFMPEGDECODERPRIVATE_H 109 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/IAudioDecoder.cpp: -------------------------------------------------------------------------------- 1 | #include "IAudioDecoder.h" 2 | 3 | QSAPI_USING_NAMESPACE 4 | 5 | IAudioDecoder::IAudioDecoder(QObject *parent) : QObject(parent) { 6 | } 7 | 8 | IAudioDecoder::~IAudioDecoder() { 9 | } 10 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/IAudioDecoder.h: -------------------------------------------------------------------------------- 1 | #ifndef IAUDIODECODER_H 2 | #define IAUDIODECODER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "NAudio/WaveStream.h" 8 | #include "QsMediaNamespace.h" 9 | 10 | QSAPI_BEGIN_NAMESPACE 11 | 12 | class QSMEDIA_API IAudioDecoder : public QObject, public NAudio::WaveStream { 13 | Q_OBJECT 14 | public: 15 | explicit IAudioDecoder(QObject *parent = nullptr); 16 | ~IAudioDecoder(); 17 | 18 | public: 19 | virtual bool open(const QString &filename, const QsMedia::WaveArguments &args = {}) = 0; 20 | virtual void close() = 0; 21 | 22 | virtual bool isOpen() const = 0; 23 | 24 | /** 25 | * @brief The original format of the processed audio 26 | * 27 | * @return NAudio::WaveFormat 28 | */ 29 | virtual NAudio::WaveFormat inFormat() const = 0; 30 | }; 31 | 32 | QSAPI_END_NAMESPACE 33 | 34 | #define QsApi_IAudioDecoder_IID "org.ChorusKit.QsLib.IAudioDecoder" 35 | 36 | QT_BEGIN_NAMESPACE 37 | Q_DECLARE_INTERFACE(QsApi::IAudioDecoder, QsApi_IAudioDecoder_IID) 38 | QT_END_NAMESPACE 39 | 40 | #endif // IAUDIODECODER_H 41 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/IAudioEncoder.cpp: -------------------------------------------------------------------------------- 1 | #include "IAudioEncoder.h" 2 | 3 | QSAPI_USING_NAMESPACE 4 | 5 | IAudioEncoder::IAudioEncoder(QObject *parent) : QObject(parent) { 6 | } 7 | 8 | IAudioEncoder::~IAudioEncoder() { 9 | } 10 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/IAudioEncoder.h: -------------------------------------------------------------------------------- 1 | #ifndef IAUDIOENCODER_H 2 | #define IAUDIOENCODER_H 3 | 4 | #include 5 | 6 | #include "QsMediaGlobal.h" 7 | 8 | QSAPI_BEGIN_NAMESPACE 9 | 10 | class QSMEDIA_API IAudioEncoder : public QObject { 11 | Q_OBJECT 12 | public: 13 | explicit IAudioEncoder(QObject *parent = nullptr); 14 | ~IAudioEncoder(); 15 | }; 16 | 17 | QSAPI_END_NAMESPACE 18 | 19 | #define QsApi_IAudioEncoder_IID "org.ChorusKit.QsLib.IAudioEncoder" 20 | 21 | QT_BEGIN_NAMESPACE 22 | Q_DECLARE_INTERFACE(QsApi::IAudioEncoder, QsApi_IAudioEncoder_IID) 23 | QT_END_NAMESPACE 24 | 25 | #endif // IAUDIOENCODER_H 26 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/IAudioPlayback.h: -------------------------------------------------------------------------------- 1 | #ifndef IAUDIOPLAYBACK_H 2 | #define IAUDIOPLAYBACK_H 3 | 4 | #include 5 | 6 | #include "Api/IAudioDecoder.h" 7 | #include "QsMediaNamespace.h" 8 | 9 | QSAPI_BEGIN_NAMESPACE 10 | 11 | class IAudioPlaybackPrivate; 12 | 13 | class QSMEDIA_API IAudioPlayback : public QObject { 14 | Q_OBJECT 15 | Q_DECLARE_PRIVATE(IAudioPlayback) 16 | public: 17 | explicit IAudioPlayback(QObject *parent = nullptr); 18 | ~IAudioPlayback(); 19 | 20 | enum PlaybackState { 21 | Playing, 22 | Stopped, 23 | }; 24 | 25 | public: 26 | /** 27 | * @brief Open audio device and get ready 28 | * 29 | * @param args Audio device arguments 30 | */ 31 | bool setup(const QsMedia::PlaybackArguments &args); 32 | 33 | /** 34 | * @brief Close audio device 35 | */ 36 | void dispose(); 37 | 38 | /** 39 | * @brief Return if the audio device is ready 40 | */ 41 | bool isAvailable() const; 42 | 43 | void setDecoder(IAudioDecoder *decoder); 44 | 45 | /** 46 | * @brief Return if the decoder is ready 47 | */ 48 | bool isReady() const; 49 | 50 | void play(); 51 | void stop(); 52 | 53 | PlaybackState state() const; 54 | bool isPlaying() const; 55 | 56 | virtual QStringList drivers() const; 57 | virtual QString currentDriver() const; 58 | virtual bool setDriver(const QString &driver); 59 | 60 | virtual QStringList devices() const; 61 | virtual QString currentDevice() const; 62 | virtual bool setDevice(const QString &device); 63 | 64 | int bufferSamples() const; 65 | int sampleRate() const; 66 | int channels() const; 67 | 68 | protected: 69 | IAudioPlayback(IAudioPlaybackPrivate &d, QObject *parent = nullptr); 70 | 71 | QScopedPointer d_ptr; 72 | 73 | signals: 74 | void stateChanged(); 75 | void driverChanged(); 76 | 77 | void deviceChanged(); 78 | void deviceAdded(); 79 | void deviceRemoved(); 80 | }; 81 | 82 | QSAPI_END_NAMESPACE 83 | 84 | #define QsApi_IAudioPlayback_IID "org.ChorusKit.QsLib.IAudioPlayback" 85 | 86 | QT_BEGIN_NAMESPACE 87 | Q_DECLARE_INTERFACE(QsApi::IAudioPlayback, QsApi_IAudioPlayback_IID) 88 | QT_END_NAMESPACE 89 | 90 | #endif // IAUDIOPLAYBACK_H 91 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/factories/AudioDecoderFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "AudioDecoderFactory.h" 2 | 3 | #include "IAudioDecoder.h" 4 | #include "Api/interfaces/IAudioDecoderPlugin.h" 5 | 6 | #include 7 | 8 | QSAPI_BEGIN_NAMESPACE 9 | 10 | #if QT_CONFIG(settings) 11 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, 12 | (QsApi_IAudioDecoderPlugin_IID, QLatin1String("/audiodecoders"), Qt::CaseInsensitive)) 13 | #endif 14 | 15 | QStringList AudioDecoderFactory::keys() { 16 | #if QT_CONFIG(settings) 17 | return loader()->keyMap().values(); 18 | #else 19 | return QStringList(); 20 | #endif 21 | } 22 | 23 | QString AudioDecoderFactory::requested() { 24 | QByteArray env = qgetenv("QSAPI_AUDIO_DECODER"); 25 | return env.isNull() ? "FFmpegDecoder" : QString::fromLocal8Bit(env); 26 | } 27 | 28 | IAudioDecoder *AudioDecoderFactory::create(const QString &key, QObject *parent) { 29 | #if QT_CONFIG(settings) 30 | if (!key.isEmpty()) { 31 | IAudioDecoder *inst = qLoadPlugin(loader(), key, parent); 32 | if (inst) 33 | return inst; 34 | delete inst; 35 | } 36 | #else 37 | Q_UNUSED(key); 38 | #endif 39 | return nullptr; 40 | } 41 | 42 | IAudioDecoder *AudioDecoderFactory::create(QObject *parent) { 43 | return create(requested(), parent); 44 | } 45 | 46 | QSAPI_END_NAMESPACE -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/factories/AudioDecoderFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIODECODERFACTORY_H 2 | #define AUDIODECODERFACTORY_H 3 | 4 | #include 5 | #include 6 | 7 | #include "QsMediaGlobal.h" 8 | 9 | QSAPI_BEGIN_NAMESPACE 10 | 11 | class IAudioDecoder; 12 | 13 | class QSMEDIA_API AudioDecoderFactory { 14 | public: 15 | static QStringList keys(); 16 | static QString requested(); 17 | static IAudioDecoder *create(const QString &key, QObject *parent); 18 | static IAudioDecoder *create(QObject *parent); 19 | }; 20 | 21 | QSAPI_END_NAMESPACE 22 | 23 | #endif // AUDIODECODERFACTORY_H 24 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/factories/AudioEncoderFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "AudioEncoderFactory.h" 2 | 3 | #include "IAudioEncoder.h" 4 | #include "Api/interfaces/IAudioEncoderPlugin.h" 5 | 6 | #include 7 | 8 | QSAPI_BEGIN_NAMESPACE 9 | 10 | #if QT_CONFIG(settings) 11 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, 12 | (QsApi_IAudioEncoderPlugin_IID, QLatin1String("/audioencoders"), Qt::CaseInsensitive)) 13 | #endif 14 | 15 | QStringList AudioEncoderFactory::keys() { 16 | #if QT_CONFIG(settings) 17 | return loader()->keyMap().values(); 18 | #else 19 | return QStringList(); 20 | #endif 21 | } 22 | 23 | QString AudioEncoderFactory::requested() { 24 | QByteArray env = qgetenv("QSAPI_AUDIO_ENCODER"); 25 | return env.isNull() ? "FFmpegEncoder" : QString::fromLocal8Bit(env); 26 | } 27 | 28 | IAudioEncoder *AudioEncoderFactory::create(const QString &key, QObject *parent) { 29 | #if QT_CONFIG(settings) 30 | if (!key.isEmpty()) { 31 | IAudioEncoder *inst = qLoadPlugin(loader(), key, parent); 32 | if (inst) 33 | return inst; 34 | delete inst; 35 | } 36 | #else 37 | Q_UNUSED(key); 38 | #endif 39 | return nullptr; 40 | } 41 | 42 | IAudioEncoder *AudioEncoderFactory::create(QObject *parent) { 43 | return create(requested(), parent); 44 | } 45 | 46 | QSAPI_END_NAMESPACE -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/factories/AudioEncoderFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIOENCODERFACTORY_H 2 | #define AUDIOENCODERFACTORY_H 3 | 4 | #include 5 | #include 6 | 7 | #include "QsMediaGlobal.h" 8 | 9 | QSAPI_BEGIN_NAMESPACE 10 | 11 | class IAudioEncoder; 12 | 13 | class QSMEDIA_API AudioEncoderFactory { 14 | public: 15 | static QStringList keys(); 16 | static QString requested(); 17 | static IAudioEncoder *create(const QString &key, QObject *parent); 18 | static IAudioEncoder *create(QObject *parent); 19 | }; 20 | 21 | QSAPI_END_NAMESPACE 22 | 23 | #endif // AUDIOENCODERFACTORY_H 24 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/factories/AudioPlaybackFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "AudioPlaybackFactory.h" 2 | 3 | #include "IAudioPlayback.h" 4 | #include "Api/interfaces/IAudioPlaybackPlugin.h" 5 | 6 | #include 7 | 8 | QSAPI_BEGIN_NAMESPACE 9 | 10 | #if QT_CONFIG(settings) 11 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, 12 | (QsApi_IAudioPlaybackPlugin_IID, QLatin1String("/audioplaybacks"), Qt::CaseInsensitive)) 13 | #endif 14 | 15 | QStringList AudioPlaybackFactory::keys() { 16 | #if QT_CONFIG(settings) 17 | return loader()->keyMap().values(); 18 | #else 19 | return QStringList(); 20 | #endif 21 | } 22 | 23 | QString AudioPlaybackFactory::requested() { 24 | QByteArray env = qgetenv("QSAPI_AUDIO_PLAYBACK"); 25 | return env.isNull() ? "SDLPlayback" : QString::fromLocal8Bit(env); 26 | } 27 | 28 | IAudioPlayback *AudioPlaybackFactory::create(const QString &key, QObject *parent) { 29 | #if QT_CONFIG(settings) 30 | if (!key.isEmpty()) { 31 | IAudioPlayback *inst = qLoadPlugin(loader(), key, parent); 32 | if (inst) 33 | return inst; 34 | delete inst; 35 | } 36 | #else 37 | Q_UNUSED(key); 38 | #endif 39 | return nullptr; 40 | } 41 | 42 | IAudioPlayback *AudioPlaybackFactory::create(QObject *parent) { 43 | return create(requested(), parent); 44 | } 45 | 46 | QSAPI_END_NAMESPACE -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/factories/AudioPlaybackFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIOPLAYBACKFACTORYH 2 | #define AUDIOPLAYBACKFACTORYH 3 | 4 | #include 5 | #include 6 | 7 | #include "QsMediaGlobal.h" 8 | 9 | QSAPI_BEGIN_NAMESPACE 10 | 11 | class IAudioPlayback; 12 | 13 | class QSMEDIA_API AudioPlaybackFactory { 14 | public: 15 | static QStringList keys(); 16 | static QString requested(); 17 | static IAudioPlayback *create(const QString &key, QObject *parent); 18 | static IAudioPlayback *create(QObject *parent); 19 | }; 20 | 21 | QSAPI_END_NAMESPACE 22 | 23 | #endif // AUDIOPLAYBACKFACTORYH 24 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/interfaces/IAudioDecoderPlugin.cpp: -------------------------------------------------------------------------------- 1 | #include "IAudioDecoderPlugin.h" 2 | 3 | QSAPI_BEGIN_NAMESPACE 4 | 5 | IAudioDecoderPlugin::IAudioDecoderPlugin(QObject *parent) : QObject(parent) { 6 | } 7 | 8 | IAudioDecoderPlugin::~IAudioDecoderPlugin() { 9 | } 10 | 11 | QSAPI_END_NAMESPACE -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/interfaces/IAudioDecoderPlugin.h: -------------------------------------------------------------------------------- 1 | #ifndef IAUDIODECODERPLUGIN_H 2 | #define IAUDIODECODERPLUGIN_H 3 | 4 | #include 5 | 6 | #include "QsMediaGlobal.h" 7 | 8 | QSAPI_BEGIN_NAMESPACE 9 | 10 | class IAudioDecoder; 11 | 12 | class QSMEDIA_API IAudioDecoderPlugin : public QObject { 13 | Q_OBJECT 14 | public: 15 | explicit IAudioDecoderPlugin(QObject *parent = nullptr); 16 | ~IAudioDecoderPlugin(); 17 | 18 | virtual IAudioDecoder *create(const QString &key, QObject *parent) = 0; 19 | }; 20 | 21 | QSAPI_END_NAMESPACE 22 | 23 | #define QsApi_IAudioDecoderPlugin_IID "org.ChorusKit.QsLib.IAudioDecoderPlugin" 24 | 25 | QT_BEGIN_NAMESPACE 26 | Q_DECLARE_INTERFACE(QsApi::IAudioDecoderPlugin, QsApi_IAudioDecoderPlugin_IID) 27 | QT_END_NAMESPACE 28 | 29 | #endif // IAUDIODECODERPLUGIN_H 30 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/interfaces/IAudioEncoderPlugin.cpp: -------------------------------------------------------------------------------- 1 | #include "IAudioEncoderPlugin.h" 2 | 3 | QSAPI_BEGIN_NAMESPACE 4 | 5 | IAudioEncoderPlugin::IAudioEncoderPlugin(QObject *parent) : QObject(parent) { 6 | } 7 | 8 | IAudioEncoderPlugin::~IAudioEncoderPlugin() { 9 | } 10 | 11 | QSAPI_END_NAMESPACE -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/interfaces/IAudioEncoderPlugin.h: -------------------------------------------------------------------------------- 1 | #ifndef IAUDIOENCODERPLUGIN_H 2 | #define IAUDIOENCODERPLUGIN_H 3 | 4 | #include 5 | 6 | #include "QsMediaGlobal.h" 7 | 8 | QSAPI_BEGIN_NAMESPACE 9 | 10 | class IAudioEncoder; 11 | 12 | class QSMEDIA_API IAudioEncoderPlugin : public QObject { 13 | Q_OBJECT 14 | public: 15 | explicit IAudioEncoderPlugin(QObject *parent = nullptr); 16 | ~IAudioEncoderPlugin(); 17 | 18 | virtual IAudioEncoder *create(const QString &key, QObject *parent) = 0; 19 | }; 20 | 21 | QSAPI_END_NAMESPACE 22 | 23 | #define QsApi_IAudioEncoderPlugin_IID "org.ChorusKit.QsLib.IAudioEncoderPlugin" 24 | 25 | QT_BEGIN_NAMESPACE 26 | Q_DECLARE_INTERFACE(QsApi::IAudioEncoderPlugin, QsApi_IAudioEncoderPlugin_IID) 27 | QT_END_NAMESPACE 28 | 29 | #endif // IAUDIOENCODERPLUGIN_H 30 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/interfaces/IAudioPlaybackPlugin.cpp: -------------------------------------------------------------------------------- 1 | #include "IAudioPlaybackPlugin.h" 2 | 3 | QSAPI_BEGIN_NAMESPACE 4 | 5 | IAudioPlaybackPlugin::IAudioPlaybackPlugin(QObject *parent) : QObject(parent) { 6 | } 7 | 8 | IAudioPlaybackPlugin::~IAudioPlaybackPlugin() { 9 | } 10 | 11 | QSAPI_END_NAMESPACE -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/interfaces/IAudioPlaybackPlugin.h: -------------------------------------------------------------------------------- 1 | #ifndef IAUDIOPLAYBACKPLUGIN_H 2 | #define IAUDIOPLAYBACKPLUGIN_H 3 | 4 | #include 5 | 6 | #include "QsMediaGlobal.h" 7 | 8 | QSAPI_BEGIN_NAMESPACE 9 | 10 | class IAudioPlayback; 11 | 12 | class QSMEDIA_API IAudioPlaybackPlugin : public QObject { 13 | Q_OBJECT 14 | public: 15 | explicit IAudioPlaybackPlugin(QObject *parent = nullptr); 16 | ~IAudioPlaybackPlugin(); 17 | 18 | virtual IAudioPlayback *create(const QString &key, QObject *parent) = 0; 19 | }; 20 | 21 | QSAPI_END_NAMESPACE 22 | 23 | #define QsApi_IAudioPlaybackPlugin_IID "org.ChorusKit.QsLib.IAudioPlaybackPlugin" 24 | 25 | QT_BEGIN_NAMESPACE 26 | Q_DECLARE_INTERFACE(QsApi::IAudioPlaybackPlugin, QsApi_IAudioPlaybackPlugin_IID) 27 | QT_END_NAMESPACE 28 | 29 | #endif // IAUDIOPLAYBACKPLUGIN_H 30 | -------------------------------------------------------------------------------- /src/libs/qsmedia/Api/private/IAudioPlayback_p.h: -------------------------------------------------------------------------------- 1 | #ifndef IAUDIOPLAYBACKPRIVATE_H 2 | #define IAUDIOPLAYBACKPRIVATE_H 3 | 4 | #include "../IAudioPlayback.h" 5 | 6 | QSAPI_BEGIN_NAMESPACE 7 | 8 | class QSMEDIA_API IAudioPlaybackPrivate { 9 | Q_DECLARE_PUBLIC(IAudioPlayback) 10 | public: 11 | IAudioPlaybackPrivate(); 12 | virtual ~IAudioPlaybackPrivate(); 13 | 14 | void init(); 15 | 16 | virtual bool setup(const QVariantMap &args); 17 | virtual void dispose(); 18 | 19 | virtual void play(); 20 | virtual void stop(); 21 | 22 | IAudioPlayback *q_ptr; 23 | 24 | IAudioDecoder *decoder; 25 | bool available; 26 | 27 | // Atomic int as playback state 28 | volatile int state; 29 | 30 | // Arguments 31 | int bufferSamples; 32 | int sampleRate; 33 | int channels; 34 | }; 35 | 36 | QSAPI_END_NAMESPACE 37 | 38 | #endif // IAUDIOPLAYBACKPRIVATE_H 39 | -------------------------------------------------------------------------------- /src/libs/qsmedia/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(QsMedia) 2 | 3 | set(CMAKE_AUTOMOC ON) 4 | set(CMAKE_AUTORCC ON) 5 | set(CMAKE_AUTOUIC ON) 6 | 7 | file(GLOB_RECURSE _src *.h *.cpp) 8 | 9 | add_library(${PROJECT_NAME} STATIC ${_src}) 10 | 11 | target_compile_definitions(${PROJECT_NAME} PUBLIC QSMEDIA_STATIC) 12 | 13 | target_include_directories(${PROJECT_NAME} PUBLIC .) 14 | 15 | target_include_directories(${PROJECT_NAME} PRIVATE Api NAudio 16 | ${Qt${QT_VERSION_MAJOR}Core_PRIVATE_INCLUDE_DIRS} 17 | ) 18 | 19 | target_link_libraries(${PROJECT_NAME} PUBLIC 20 | Qt${QT_VERSION_MAJOR}::Core 21 | ) -------------------------------------------------------------------------------- /src/libs/qsmedia/NAudio/NAudioGlobal.h: -------------------------------------------------------------------------------- 1 | #ifndef NAUDIOGLOBAL_H 2 | #define NAUDIOGLOBAL_H 3 | 4 | #define NAUDIO_BEGIN_NAMESPACE namespace NAudio { 5 | #define NAUDIO_END_NAMESPACE } 6 | #define NAUDIO_USING_NAMESPACE using namespace NAudio; 7 | 8 | #endif // NAUDIOGLOBAL_H -------------------------------------------------------------------------------- /src/libs/qsmedia/NAudio/WaveFormat.h: -------------------------------------------------------------------------------- 1 | #ifndef WAVEFORMAT_H 2 | #define WAVEFORMAT_H 3 | 4 | #include 5 | #include 6 | 7 | #include "QsMediaGlobal.h" 8 | #include "WaveFormatEncoding.h" 9 | 10 | NAUDIO_BEGIN_NAMESPACE 11 | 12 | class QSMEDIA_API WaveFormat { 13 | protected: 14 | NAudio::WaveFormatEncoding waveFormatTag; 15 | short channels; 16 | int sampleRate; 17 | int averageBytesPerSecond; 18 | short blockAlign; 19 | short bitsPerSample; 20 | short extraSize; 21 | 22 | public: 23 | WaveFormat() : WaveFormat(44100, 16, 2) { 24 | } 25 | 26 | WaveFormat(int sampleRate, int channels) : WaveFormat(sampleRate, 16, channels) { 27 | } 28 | 29 | WaveFormat(int rate, int bits, int channels); 30 | 31 | int ConvertLatencyToByteSize(int milliseconds) const; 32 | 33 | static WaveFormat CreateCustomFormat(NAudio::WaveFormatEncoding tag, int sampleRate, 34 | int channels, int averageBytesPerSecond, int blockAlign, 35 | int bitsPerSample); 36 | 37 | static WaveFormat CreateALawFormat(int sampleRate, int channels); 38 | 39 | static WaveFormat CreateMuLawFormat(int sampleRate, int channels); 40 | 41 | static WaveFormat CreateIeeeFloatWaveFormat(int sampleRate, int channels); 42 | 43 | static WaveFormat FromFormatChunk(QIODevice *br, int formatChunkLength); 44 | 45 | protected: 46 | bool ReadWaveFormat(QIODevice *br, int formatChunkLength); 47 | 48 | public: 49 | WaveFormat(QIODevice *br); 50 | 51 | QString toString() const; 52 | 53 | bool operator==(const WaveFormat &waveFormat) const; 54 | 55 | int toHashCode() const; 56 | 57 | NAudio::WaveFormatEncoding Encoding() const; 58 | 59 | virtual void Serialize(QIODevice *writer); 60 | 61 | inline int Channels() const { 62 | return channels; 63 | }; 64 | 65 | inline int SampleRate() const { 66 | return sampleRate; 67 | } 68 | 69 | inline int AverageBytesPerSecond() const { 70 | return averageBytesPerSecond; 71 | } 72 | 73 | inline virtual int BlockAlign() const { 74 | return blockAlign; 75 | } 76 | 77 | inline int BitsPerSample() const { 78 | return bitsPerSample; 79 | } 80 | 81 | inline int ExtraSize() const { 82 | return extraSize; 83 | } 84 | }; 85 | 86 | NAUDIO_END_NAMESPACE 87 | 88 | #endif // WAVEFORMAT_H 89 | -------------------------------------------------------------------------------- /src/libs/qsmedia/NAudio/WaveFormatEncoding.cpp: -------------------------------------------------------------------------------- 1 | #include "WaveFormatEncoding.h" 2 | -------------------------------------------------------------------------------- /src/libs/qsmedia/NAudio/WaveFormatExtraData.cpp: -------------------------------------------------------------------------------- 1 | #include "WaveFormatExtraData.h" 2 | 3 | NAUDIO_BEGIN_NAMESPACE 4 | 5 | WaveFormatExtraData::WaveFormatExtraData() { 6 | memset(extraData, 0, sizeof(extraData)); 7 | } 8 | 9 | WaveFormatExtraData::WaveFormatExtraData(QIODevice *reader) : WaveFormat(reader) { 10 | this->ReadExtraData(reader); 11 | } 12 | 13 | void WaveFormatExtraData::ReadExtraData(QIODevice *reader) { 14 | if (this->extraSize <= (short) 0) 15 | return; 16 | reader->read(this->extraData, this->extraSize); 17 | } 18 | 19 | void WaveFormatExtraData::Serialize(QIODevice *writer) { 20 | WaveFormat::Serialize(writer); 21 | if (this->extraSize <= (short) 0) 22 | return; 23 | writer->write(this->extraData, this->extraSize); 24 | } 25 | 26 | NAUDIO_END_NAMESPACE -------------------------------------------------------------------------------- /src/libs/qsmedia/NAudio/WaveFormatExtraData.h: -------------------------------------------------------------------------------- 1 | #ifndef WAVEFORMATEXTRADATA_H 2 | #define WAVEFORMATEXTRADATA_H 3 | 4 | #include "WaveFormat.h" 5 | 6 | #include "QsMediaGlobal.h" 7 | 8 | NAUDIO_BEGIN_NAMESPACE 9 | 10 | class QSMEDIA_API WaveFormatExtraData : public WaveFormat { 11 | private: 12 | char extraData[100]; 13 | 14 | public: 15 | const char *ExtraData() const { 16 | return extraData; 17 | } 18 | 19 | WaveFormatExtraData(); 20 | 21 | WaveFormatExtraData(QIODevice *reader); 22 | 23 | void ReadExtraData(QIODevice *reader); 24 | 25 | void Serialize(QIODevice *writer); 26 | }; 27 | 28 | NAUDIO_END_NAMESPACE 29 | 30 | #endif // WAVEFORMATEXTRADATA_H 31 | -------------------------------------------------------------------------------- /src/libs/qsmedia/NAudio/WaveStream.cpp: -------------------------------------------------------------------------------- 1 | #include "WaveStream.h" 2 | 3 | NAUDIO_BEGIN_NAMESPACE 4 | 5 | static void set_pos_bounded(WaveStream *stream, qint64 pos) { 6 | if (pos > stream->Length()) 7 | stream->SetPosition(stream->Length()); 8 | else if (pos < 0) 9 | stream->SetPosition(0); 10 | else 11 | stream->SetPosition(pos); 12 | } 13 | 14 | WaveStream::WaveStream() { 15 | } 16 | 17 | WaveStream::~WaveStream() { 18 | } 19 | 20 | int WaveStream::BlockAlign() const { 21 | return Format().BlockAlign(); 22 | } 23 | 24 | void WaveStream::Flush() { 25 | } 26 | 27 | qint64 WaveStream::Seek(qint64 offset, WaveStream::SeekOrigin origin) { 28 | switch (origin) { 29 | case SeekOrigin::Begin: 30 | SetPosition(offset); 31 | break; 32 | case SeekOrigin::Current: 33 | SetPosition(Position() + offset); 34 | break; 35 | default: 36 | SetPosition(Length() + offset); 37 | break; 38 | } 39 | return Position(); 40 | } 41 | 42 | void WaveStream::Skip(qint64 msecs) { 43 | qint64 num = Position() + qint64(Format().AverageBytesPerSecond() * double(msecs) / 1000); 44 | set_pos_bounded(this, num); 45 | } 46 | 47 | qint64 WaveStream::CurrentTime() const { 48 | return double(Position()) / Format().AverageBytesPerSecond() * 1000; 49 | } 50 | 51 | void WaveStream::SetCurrentTime(qint64 msecs) { 52 | qint64 num = double(msecs) * Format().AverageBytesPerSecond() / 1000; 53 | set_pos_bounded(this, num); 54 | } 55 | 56 | qint64 WaveStream::TotalTime() const { 57 | return double(Length()) / Format().AverageBytesPerSecond() * 1000; 58 | } 59 | 60 | void WaveStream::SkipSamples(qint64 count) { 61 | qint64 num = Position() + qint64(double(count) / int(Format().BitsPerSample() / 8)); 62 | set_pos_bounded(this, num); 63 | } 64 | 65 | qint64 WaveStream::TotalSamples() const { 66 | return double(Length()) / int(Format().BitsPerSample() / 8); 67 | } 68 | 69 | void WaveStream::SetCurrentSample(qint64 count) { 70 | qint64 num = double(count) / int(Format().BitsPerSample() / 8); 71 | set_pos_bounded(this, num); 72 | } 73 | 74 | qint64 WaveStream::CurrentSample() const { 75 | return double(Position()) / int(Format().BitsPerSample() / 8); 76 | } 77 | 78 | int WaveStream::Read(float *buffer, int offset, int count) { 79 | return Read((char *) buffer, offset * 4, count * 4); 80 | } 81 | 82 | bool WaveStream::HasData(int count) const { 83 | Q_UNUSED(count); 84 | return Position() < Length(); 85 | } 86 | 87 | NAUDIO_END_NAMESPACE -------------------------------------------------------------------------------- /src/libs/qsmedia/NAudio/WaveStream.h: -------------------------------------------------------------------------------- 1 | #ifndef WAVESTREAM_H 2 | #define WAVESTREAM_H 3 | 4 | #include 5 | 6 | #include "WaveFormat.h" 7 | 8 | NAUDIO_BEGIN_NAMESPACE 9 | 10 | class QSMEDIA_API WaveStream { 11 | public: 12 | WaveStream(); 13 | ~WaveStream(); 14 | 15 | /** 16 | * @brief The reference used to determine audio position 17 | * Override when inherited as a resampler 18 | * 19 | * @return WaveFormat 20 | */ 21 | virtual WaveFormat Format() const = 0; 22 | virtual int BlockAlign() const; 23 | virtual void Flush(); 24 | 25 | virtual int Read(char *buffer, int offset, int count) = 0; 26 | virtual int Read(float *buffer, int offset, int count); 27 | 28 | // Expressed in bytes 29 | virtual void SetPosition(qint64 pos) = 0; 30 | virtual qint64 Position() const = 0; 31 | virtual qint64 Length() const = 0; 32 | 33 | enum SeekOrigin { 34 | // These constants match Win32's FILE_BEGIN, FILE_CURRENT, and FILE_END 35 | Begin = 0, 36 | Current = 1, 37 | End = 2, 38 | }; 39 | qint64 Seek(qint64 offset, SeekOrigin origin); 40 | 41 | // Expressed in milliseconds 42 | void Skip(qint64 msecs); 43 | qint64 CurrentTime() const; 44 | void SetCurrentTime(qint64 msecs); 45 | qint64 TotalTime() const; 46 | 47 | // Expressed in samples 48 | void SkipSamples(qint64 count); 49 | qint64 TotalSamples() const; 50 | void SetCurrentSample(qint64 count); 51 | qint64 CurrentSample() const; 52 | 53 | virtual bool HasData(int count) const; 54 | }; 55 | 56 | NAUDIO_END_NAMESPACE 57 | 58 | #endif // WAVESTREAM_H 59 | -------------------------------------------------------------------------------- /src/libs/qsmedia/QsMediaGlobal.h: -------------------------------------------------------------------------------- 1 | #ifndef QSMEDIAGLOBAL_H 2 | #define QSMEDIAGLOBAL_H 3 | 4 | #include 5 | 6 | #ifndef QSMEDIA_API 7 | # ifdef QSMEDIA_STATIC 8 | # define QSMEDIA_API 9 | # else 10 | # ifdef QSMEDIA_LIBRARY 11 | # define QSMEDIA_API Q_DECL_EXPORT 12 | # else 13 | # define QSMEDIA_API Q_DECL_IMPORT 14 | # endif 15 | # endif 16 | #endif 17 | 18 | #define QSAPI_BEGIN_NAMESPACE namespace QsApi { 19 | #define QSAPI_END_NAMESPACE } 20 | #define QSAPI_USING_NAMESPACE using namespace QsApi; 21 | 22 | #define QSMEDIA_BEGIN_NAMESPACE namespace QsMedia { 23 | #define QSMEDIA_END_NAMESPACE } 24 | 25 | #endif // QSMEDIAGLOBAL_H 26 | -------------------------------------------------------------------------------- /src/libs/qsmedia/QsMediaNamespace.h: -------------------------------------------------------------------------------- 1 | #ifndef __QSMEDIANAMESPACE_H__ 2 | #define __QSMEDIANAMESPACE_H__ 3 | 4 | #include "QsMediaGlobal.h" 5 | 6 | #include 7 | #include 8 | 9 | QSMEDIA_BEGIN_NAMESPACE 10 | struct WaveArguments { 11 | int sampleRate; 12 | int sampleFormat; // Format decided by the decoder 13 | int channels; 14 | QVariantMap custom; 15 | 16 | WaveArguments(int sampleRate = -1, int channels = -1) : WaveArguments(sampleRate, -1, channels) { 17 | } 18 | 19 | WaveArguments(int sampleRate, int sampleFormat, int channels) 20 | : sampleRate(sampleRate), sampleFormat(sampleFormat), channels(channels) { 21 | } 22 | }; 23 | 24 | struct PlaybackArguments { 25 | int sampleRate; 26 | int channels; 27 | int bufferSamples; 28 | QVariantMap custom; 29 | 30 | PlaybackArguments(int sampleRate = 44100, int channels = 2, int bufferSamples = 1024) 31 | : sampleRate(sampleRate), channels(channels), bufferSamples(bufferSamples) { 32 | } 33 | }; 34 | 35 | enum FFmpeg_AVSampleFormat { 36 | AV_SAMPLE_FMT_NONE = -1, // 0xFFFFFFFF 37 | /// unsigned 8 bits 38 | AV_SAMPLE_FMT_U8 = 0, 39 | /// signed 16 bits 40 | AV_SAMPLE_FMT_S16 = 1, 41 | /// signed 32 bits 42 | AV_SAMPLE_FMT_S32 = 2, 43 | /// float 44 | AV_SAMPLE_FMT_FLT = 3, 45 | /// double 46 | AV_SAMPLE_FMT_DBL = 4, 47 | /// unsigned 8 bits, planar 48 | AV_SAMPLE_FMT_U8P = 5, 49 | /// signed 16 bits, planar 50 | AV_SAMPLE_FMT_S16P = 6, 51 | /// signed 32 bits, planar 52 | AV_SAMPLE_FMT_S32P = 7, 53 | /// float, planar 54 | AV_SAMPLE_FMT_FLTP = 8, 55 | /// double, planar 56 | AV_SAMPLE_FMT_DBLP = 9, 57 | /// signed 64 bits 58 | AV_SAMPLE_FMT_S64 = 10, // 0x0000000A 59 | /// signed 64 bits, planar 60 | AV_SAMPLE_FMT_S64P = 11, // 0x0000000B 61 | /// Number of sample formats. DO NOT USE if linking dynamically 62 | AV_SAMPLE_FMT_NB = 12, // 0x0000000C 63 | }; 64 | 65 | QSMEDIA_END_NAMESPACE 66 | 67 | #endif // __QSMEDIANAMESPACE_H__ -------------------------------------------------------------------------------- /src/libs/rmvpe-infer/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: LLVM 4 | AccessModifierOffset: -4 5 | AlignConsecutiveAssignments: false 6 | AlignConsecutiveDeclarations: false 7 | AlignOperands: false 8 | AlignTrailingComments: false 9 | AlwaysBreakTemplateDeclarations: Yes 10 | BraceWrapping: 11 | AfterCaseLabel: true 12 | AfterClass: false 13 | AfterControlStatement: false 14 | AfterEnum: false 15 | AfterFunction: false 16 | AfterNamespace: true 17 | AfterStruct: false 18 | AfterUnion: false 19 | AfterExternBlock: false 20 | BeforeCatch: true 21 | BeforeElse: false 22 | BeforeLambdaBody: true 23 | BeforeWhile: true 24 | SplitEmptyFunction: false 25 | SplitEmptyRecord: false 26 | SplitEmptyNamespace: false 27 | BreakBeforeBraces: Custom 28 | BreakConstructorInitializers: AfterColon 29 | BreakConstructorInitializersBeforeComma: false 30 | ColumnLimit: 120 31 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 32 | IncludeCategories: 33 | - Regex: '^<.*' 34 | Priority: 1 35 | - Regex: '^".*' 36 | Priority: 2 37 | - Regex: '.*' 38 | Priority: 3 39 | IncludeIsMainRegex: '([-_](test|unittest))?$' 40 | IndentCaseBlocks: true 41 | IndentWidth: 4 42 | InsertNewlineAtEOF: true 43 | MacroBlockBegin: '' 44 | MacroBlockEnd: '' 45 | MaxEmptyLinesToKeep: 2 46 | NamespaceIndentation: All 47 | SpaceInEmptyParentheses: false 48 | SpacesInAngles: false 49 | SpacesInConditionalStatement: false 50 | SpacesInCStyleCastParentheses: false 51 | SpacesInParentheses: false 52 | TabWidth: 4 53 | ... 54 | -------------------------------------------------------------------------------- /src/libs/rmvpe-infer/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | .DS_Store 35 | */.DS_Store 36 | 37 | build-src* 38 | build/ 39 | cmake-build* 40 | *.user 41 | *.lnk 42 | Libs/* 43 | _workingDir* 44 | .vscode 45 | .idea 46 | .cache 47 | cache 48 | .vs 49 | out/ 50 | CMakeSettings.json 51 | /vcpkg 52 | /data 53 | /*.natvis 54 | 55 | *.sublime-* 56 | setup-vcpkg.json 57 | setup-vcpkg-temp* -------------------------------------------------------------------------------- /src/libs/rmvpe-infer/cmake/winrc.cmake: -------------------------------------------------------------------------------- 1 | set(_rc_content "#include 2 | 3 | #ifndef VS_VERSION_INFO 4 | #define VS_VERSION_INFO 1 5 | #endif 6 | 7 | #define _STRINGIFY(x) #x 8 | #define STRINGIFY(x) _STRINGIFY(x) 9 | 10 | VS_VERSION_INFO VERSIONINFO 11 | FILEVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},${PROJECT_VERSION_TWEAK} 12 | PRODUCTVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},${PROJECT_VERSION_TWEAK} 13 | { 14 | BLOCK \"StringFileInfo\" 15 | { 16 | // U.S. English - Windows, Multilingual 17 | BLOCK \"040904E4\" 18 | { 19 | VALUE \"FileDescription\", STRINGIFY(${RC_DESCRIPTION}) 20 | VALUE \"FileVersion\", STRINGIFY(${PROJECT_VERSION}) 21 | VALUE \"ProductName\", STRINGIFY(${PROJECT_NAME}) 22 | VALUE \"ProductVersion\", STRINGIFY(${PROJECT_VERSION}) 23 | VALUE \"LegalCopyright\", STRINGIFY(${RC_COPYRIGHT}) 24 | } 25 | } 26 | BLOCK \"VarFileInfo\" 27 | { 28 | VALUE \"Translation\", 0x409, 1252 // 1252 = 0x04E4 29 | } 30 | }") 31 | 32 | set(_rc_file ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_res.rc) 33 | file(WRITE ${_rc_file} ${_rc_content}) 34 | target_sources(${PROJECT_NAME} PRIVATE ${_rc_file}) -------------------------------------------------------------------------------- /src/libs/rmvpe-infer/include/rmvpe-infer/Provider.h: -------------------------------------------------------------------------------- 1 | #ifndef RMVPEPROVIDER_H 2 | #define RMVPEPROVIDER_H 3 | 4 | namespace Rmvpe 5 | { 6 | enum class ExecutionProvider { CPU, DML, CUDA }; 7 | } 8 | 9 | #endif // RMVPEPROVIDER_H 10 | -------------------------------------------------------------------------------- /src/libs/rmvpe-infer/include/rmvpe-infer/Rmvpe.h: -------------------------------------------------------------------------------- 1 | #ifndef RMVPE_H 2 | #define RMVPE_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace Rmvpe 12 | { 13 | class RmvpeModel; 14 | 15 | struct RmvpeRes { 16 | float offset; // ms 17 | std::vector f0; 18 | std::vector uv; 19 | }; 20 | 21 | class RMVPE_INFER_EXPORT Rmvpe { 22 | public: 23 | explicit Rmvpe(const std::filesystem::path &modelPath, ExecutionProvider provider, int device_id); 24 | ~Rmvpe(); 25 | 26 | bool is_open() const; 27 | 28 | bool get_f0(const std::filesystem::path &filepath, float threshold, std::vector &res, 29 | std::string &msg, const std::function &progressChanged) const; 30 | 31 | void terminate() const; 32 | 33 | std::unique_ptr m_rmvpe; 34 | }; 35 | } // namespace Rmvpe 36 | 37 | #endif // RMVPE_H 38 | -------------------------------------------------------------------------------- /src/libs/rmvpe-infer/include/rmvpe-infer/RmvpeGlobal.h: -------------------------------------------------------------------------------- 1 | #ifndef RMVPEGLOBAL_H 2 | #define RMVPEGLOBAL_H 3 | 4 | #ifdef _MSC_VER 5 | #define RMVPE_INFER_DECL_EXPORT __declspec(dllexport) 6 | #define RMVPE_INFER_DECL_IMPORT __declspec(dllimport) 7 | #else 8 | #define RMVPE_INFER_DECL_EXPORT __attribute__((visibility("default"))) 9 | #define RMVPE_INFER_DECL_IMPORT __attribute__((visibility("default"))) 10 | #endif 11 | 12 | #ifndef RMVPE_INFER_EXPORT 13 | #ifdef RMVPE_INFER_STATIC 14 | #define RMVPE_INFER_EXPORT 15 | #else 16 | #ifdef RMVPE_INFER_LIBRARY 17 | #define RMVPE_INFER_EXPORT RMVPE_INFER_DECL_EXPORT 18 | #else 19 | #define RMVPE_INFER_EXPORT RMVPE_INFER_DECL_IMPORT 20 | #endif 21 | #endif 22 | #endif 23 | 24 | #endif // RMVPEGLOBAL_H 25 | -------------------------------------------------------------------------------- /src/libs/rmvpe-infer/include/rmvpe-infer/RmvpeModel.h: -------------------------------------------------------------------------------- 1 | #ifndef RMVPEMODEL_H 2 | #define RMVPEMODEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Rmvpe 11 | { 12 | class RmvpeModel { 13 | public: 14 | explicit RmvpeModel(const std::filesystem::path &modelPath, ExecutionProvider provider, int device_id); 15 | ~RmvpeModel(); 16 | 17 | bool is_open() const; 18 | // Forward pass through the model 19 | bool forward(const std::vector &waveform_data, float threshold, std::vector &f0, 20 | std::vector &uv, std::string &msg); 21 | 22 | void terminate(); 23 | 24 | private: 25 | Ort::Env m_env; 26 | Ort::RunOptions run_options; 27 | Ort::SessionOptions m_session_options; 28 | Ort::Session m_session; 29 | Ort::AllocatorWithDefaultOptions m_allocator; 30 | const char *m_waveform_input_name; // Name of the waveform input 31 | const char *m_threshold_input_name; // Name of the threshold input 32 | const char *m_f0_output_name; // Name of the f0 output 33 | const char *m_uv_output_name; // Name of the uv output 34 | 35 | #ifdef _WIN_X86 36 | Ort::MemoryInfo m_memory_info = Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU); 37 | #else 38 | Ort::MemoryInfo m_memory_info = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); 39 | #endif 40 | }; 41 | 42 | } // namespace Rmvpe 43 | 44 | #endif // RMVPEMODEL_H 45 | -------------------------------------------------------------------------------- /src/libs/rmvpe-infer/rmvpe-inferConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/rmvpe-inferTargets.cmake") 4 | -------------------------------------------------------------------------------- /src/libs/rmvpe-infer/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(TestRmvpe) 2 | 3 | add_executable(${PROJECT_NAME} main.cpp) 4 | 5 | target_link_libraries(${PROJECT_NAME} PRIVATE 6 | rmvpe-infer::rmvpe-infer 7 | ) -------------------------------------------------------------------------------- /src/libs/sdlplayback/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(SDLPlayback) 2 | 3 | set(CMAKE_AUTOMOC ON) 4 | set(CMAKE_AUTORCC ON) 5 | set(CMAKE_AUTOUIC ON) 6 | 7 | file(GLOB_RECURSE _src *.h *.cpp) 8 | 9 | add_library(${PROJECT_NAME} STATIC ${_src}) 10 | 11 | target_include_directories(${PROJECT_NAME} PUBLIC .) 12 | 13 | target_link_libraries(${PROJECT_NAME} PUBLIC 14 | QsMedia 15 | ) 16 | 17 | find_package(SDL2 REQUIRED) 18 | target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2) 19 | -------------------------------------------------------------------------------- /src/libs/sdlplayback/SDLPlayback.cpp: -------------------------------------------------------------------------------- 1 | #include "SDLPlayback.h" 2 | #include "private/SDLPlayback_p.h" 3 | 4 | #include 5 | 6 | SDLPlayback::SDLPlayback(QObject *parent) : SDLPlayback(*new SDLPlaybackPrivate(), parent) { 7 | } 8 | 9 | SDLPlayback::~SDLPlayback() { 10 | Q_D(SDLPlayback); 11 | if (d->available) { 12 | dispose(); 13 | } 14 | } 15 | 16 | QStringList SDLPlayback::drivers() const { 17 | QStringList res; 18 | const int cnt = SDL_GetNumAudioDrivers(); 19 | for (int i = 0; i < cnt; i++) { 20 | QString drv = QString::fromStdString(SDL_GetAudioDriver(i)); 21 | if (drv == "dummy" || drv == "disk") { 22 | continue; 23 | } 24 | res.append(drv); 25 | } 26 | return res; 27 | } 28 | 29 | QString SDLPlayback::currentDriver() const { 30 | Q_D(const SDLPlayback); 31 | return d->driver; 32 | } 33 | 34 | bool SDLPlayback::setDriver(const QString &driver) { 35 | Q_D(SDLPlayback); 36 | 37 | // if (state() == Playing) { 38 | // qDebug().noquote() << "SDLPlayback: Don't change audio driver when playing."; 39 | // return false; 40 | // } 41 | 42 | stop(); 43 | 44 | return d->switchDriver(driver); 45 | } 46 | 47 | QStringList SDLPlayback::devices() const { 48 | QStringList res; 49 | const int cnt = SDL_GetNumAudioDevices(0); 50 | for (int i = 0; i < cnt; i++) { 51 | res.append(QString::fromStdString(SDL_GetAudioDeviceName(i, 0))); 52 | } 53 | return res; 54 | } 55 | 56 | QString SDLPlayback::currentDevice() const { 57 | Q_D(const SDLPlayback); 58 | return d->device; 59 | } 60 | 61 | bool SDLPlayback::setDevice(const QString &device) { 62 | Q_D(SDLPlayback); 63 | 64 | // if (state() == Playing) { 65 | // qDebug().noquote() << "SDLPlayback: Don't change audio device when playing."; 66 | // return false; 67 | // } 68 | 69 | stop(); 70 | 71 | return d->switchDevId(device); 72 | } 73 | 74 | SDLPlayback::SDLPlayback(SDLPlaybackPrivate &d, QObject *parent) : IAudioPlayback(d, parent) { 75 | d.init(); 76 | } 77 | -------------------------------------------------------------------------------- /src/libs/sdlplayback/SDLPlayback.h: -------------------------------------------------------------------------------- 1 | #ifndef SDLPLAYBACK_H 2 | #define SDLPLAYBACK_H 3 | 4 | #include "Api/IAudioPlayback.h" 5 | 6 | QSAPI_USING_NAMESPACE 7 | 8 | class SDLPlaybackPrivate; 9 | 10 | class SDLPlayback final : public IAudioPlayback { 11 | Q_OBJECT 12 | Q_DECLARE_PRIVATE(SDLPlayback) 13 | public: 14 | explicit SDLPlayback(QObject *parent = nullptr); 15 | ~SDLPlayback() override; 16 | 17 | public: 18 | QStringList drivers() const override; 19 | QString currentDriver() const override; 20 | bool setDriver(const QString &driver) override; 21 | 22 | QStringList devices() const override; 23 | QString currentDevice() const override; 24 | bool setDevice(const QString &device) override; 25 | 26 | protected: 27 | explicit SDLPlayback(SDLPlaybackPrivate &d, QObject *parent = nullptr); 28 | }; 29 | 30 | #endif // SDLPLAYBACK_H 31 | -------------------------------------------------------------------------------- /src/libs/sdlplayback/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "Name": "SDLPlayback", 3 | "Version": "0.0.0.1", 4 | "Author": "Sine Striker", 5 | "License": "MIT License", 6 | "Keys": [ 7 | "SDLPlayback" 8 | ] 9 | } -------------------------------------------------------------------------------- /src/libs/sdlplayback/private/SDLPlayback_p.h: -------------------------------------------------------------------------------- 1 | #ifndef SDLPLAYBACKPRIVATE_H 2 | #define SDLPLAYBACKPRIVATE_H 3 | 4 | #include "Api/private/IAudioPlayback_p.h" 5 | 6 | #include "../SDLPlayback.h" 7 | 8 | #include 9 | #include 10 | 11 | extern "C" { 12 | #include 13 | } 14 | 15 | class SDLPlaybackPrivate : public IAudioPlaybackPrivate { 16 | Q_DECLARE_PUBLIC(SDLPlayback) 17 | public: 18 | SDLPlaybackPrivate(); 19 | ~SDLPlaybackPrivate(); 20 | 21 | void init(); 22 | 23 | bool setup(const QVariantMap &args) override; 24 | void dispose() override; 25 | 26 | void play() override; 27 | void stop() override; 28 | 29 | void switchState(IAudioPlayback::PlaybackState newState); 30 | 31 | bool switchDevId(const QString &dev); 32 | bool switchDriver(const QString &drv); 33 | 34 | static void notifyGetAudioFrame(); 35 | static void notifyStop(); 36 | static void notifyPlay(); 37 | static void notifyQuitPoll(); 38 | 39 | void workCallback(quint8 *stream, int len); 40 | 41 | void poll(); 42 | 43 | enum SDL_UserEvent { 44 | SDL_EVENT_BUFFER_END = SDL_USEREVENT + 1, 45 | SDL_EVENT_MANUAL_STOP, 46 | SDL_EVENT_MANUAL_PLAY, 47 | SDL_EVENT_QUIT_POLL, 48 | }; 49 | 50 | // 控制参数 51 | quint32 curDevId; // 当前播放设备 52 | 53 | SDL_AudioSpec spec; 54 | 55 | std::thread *producer; 56 | 57 | std::mutex mutex; 58 | 59 | struct CallbackBlock { 60 | char *audio_chunk; 61 | int audio_len; 62 | int audio_pos; 63 | }; 64 | 65 | CallbackBlock scb; 66 | 67 | QScopedArrayPointer pcm_buffer; 68 | int pcm_buffer_size; 69 | 70 | QString driver; 71 | QString device; 72 | }; 73 | 74 | #endif // SDLPLAYBACKPRIVATE_H 75 | -------------------------------------------------------------------------------- /src/libs/some-infer/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: LLVM 4 | AccessModifierOffset: -4 5 | AlignConsecutiveAssignments: false 6 | AlignConsecutiveDeclarations: false 7 | AlignOperands: false 8 | AlignTrailingComments: false 9 | AlwaysBreakTemplateDeclarations: Yes 10 | BraceWrapping: 11 | AfterCaseLabel: true 12 | AfterClass: false 13 | AfterControlStatement: false 14 | AfterEnum: false 15 | AfterFunction: false 16 | AfterNamespace: true 17 | AfterStruct: false 18 | AfterUnion: false 19 | AfterExternBlock: false 20 | BeforeCatch: true 21 | BeforeElse: false 22 | BeforeLambdaBody: true 23 | BeforeWhile: true 24 | SplitEmptyFunction: false 25 | SplitEmptyRecord: false 26 | SplitEmptyNamespace: false 27 | BreakBeforeBraces: Custom 28 | BreakConstructorInitializers: AfterColon 29 | BreakConstructorInitializersBeforeComma: false 30 | ColumnLimit: 120 31 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 32 | IncludeCategories: 33 | - Regex: '^<.*' 34 | Priority: 1 35 | - Regex: '^".*' 36 | Priority: 2 37 | - Regex: '.*' 38 | Priority: 3 39 | IncludeIsMainRegex: '([-_](test|unittest))?$' 40 | IndentCaseBlocks: true 41 | IndentWidth: 4 42 | InsertNewlineAtEOF: true 43 | MacroBlockBegin: '' 44 | MacroBlockEnd: '' 45 | MaxEmptyLinesToKeep: 2 46 | NamespaceIndentation: All 47 | SpaceInEmptyParentheses: false 48 | SpacesInAngles: false 49 | SpacesInConditionalStatement: false 50 | SpacesInCStyleCastParentheses: false 51 | SpacesInParentheses: false 52 | TabWidth: 4 53 | ... 54 | -------------------------------------------------------------------------------- /src/libs/some-infer/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | .DS_Store 35 | */.DS_Store 36 | 37 | build-src* 38 | build/ 39 | cmake-build* 40 | *.user 41 | *.lnk 42 | Libs/* 43 | _workingDir* 44 | .vscode 45 | .idea 46 | .cache 47 | cache 48 | .vs 49 | out/ 50 | CMakeSettings.json 51 | /vcpkg 52 | /data 53 | /*.natvis 54 | 55 | *.sublime-* 56 | setup-vcpkg.json 57 | setup-vcpkg-temp* -------------------------------------------------------------------------------- /src/libs/some-infer/cmake/winrc.cmake: -------------------------------------------------------------------------------- 1 | set(_rc_content "#include 2 | 3 | #ifndef VS_VERSION_INFO 4 | #define VS_VERSION_INFO 1 5 | #endif 6 | 7 | #define _STRINGIFY(x) #x 8 | #define STRINGIFY(x) _STRINGIFY(x) 9 | 10 | VS_VERSION_INFO VERSIONINFO 11 | FILEVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},${PROJECT_VERSION_TWEAK} 12 | PRODUCTVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},${PROJECT_VERSION_TWEAK} 13 | { 14 | BLOCK \"StringFileInfo\" 15 | { 16 | // U.S. English - Windows, Multilingual 17 | BLOCK \"040904E4\" 18 | { 19 | VALUE \"FileDescription\", STRINGIFY(${RC_DESCRIPTION}) 20 | VALUE \"FileVersion\", STRINGIFY(${PROJECT_VERSION}) 21 | VALUE \"ProductName\", STRINGIFY(${PROJECT_NAME}) 22 | VALUE \"ProductVersion\", STRINGIFY(${PROJECT_VERSION}) 23 | VALUE \"LegalCopyright\", STRINGIFY(${RC_COPYRIGHT}) 24 | } 25 | } 26 | BLOCK \"VarFileInfo\" 27 | { 28 | VALUE \"Translation\", 0x409, 1252 // 1252 = 0x04E4 29 | } 30 | }") 31 | 32 | set(_rc_file ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_res.rc) 33 | file(WRITE ${_rc_file} ${_rc_content}) 34 | target_sources(${PROJECT_NAME} PRIVATE ${_rc_file}) -------------------------------------------------------------------------------- /src/libs/some-infer/include/some-infer/Provider.h: -------------------------------------------------------------------------------- 1 | #ifndef SOMEPROVIDER_H 2 | #define SOMEPROVIDER_H 3 | 4 | namespace Some 5 | { 6 | enum class ExecutionProvider { CPU, DML, CUDA }; 7 | } 8 | 9 | #endif // SOMEPROVIDER_H 10 | -------------------------------------------------------------------------------- /src/libs/some-infer/include/some-infer/Some.h: -------------------------------------------------------------------------------- 1 | #ifndef SOME_H 2 | #define SOME_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace Some 12 | { 13 | class SomeModel; 14 | 15 | struct SOME_INFER_EXPORT Midi { 16 | int note, start, duration; 17 | }; 18 | 19 | struct SOME_INFER_EXPORT Dur { 20 | int note, start, duration; 21 | }; 22 | 23 | class SOME_INFER_EXPORT Some { 24 | public: 25 | explicit Some(const std::filesystem::path &modelPath, ExecutionProvider provider, int device_id); 26 | ~Some(); 27 | 28 | bool is_open() const; 29 | 30 | bool get_midi(const std::filesystem::path &filepath, std::vector &midis, float tempo, std::string &msg, 31 | const std::function &progressChanged) const; 32 | 33 | void terminate() const; 34 | 35 | private: 36 | std::unique_ptr m_some; 37 | }; 38 | } // namespace Some 39 | 40 | #endif // SOME_H 41 | -------------------------------------------------------------------------------- /src/libs/some-infer/include/some-infer/SomeGlobal.h: -------------------------------------------------------------------------------- 1 | #ifndef SOMEGLOBAL_H 2 | #define SOMEGLOBAL_H 3 | 4 | #ifdef _MSC_VER 5 | #define SOME_INFER_DECL_EXPORT __declspec(dllexport) 6 | #define SOME_INFER_DECL_IMPORT __declspec(dllimport) 7 | #else 8 | #define SOME_INFER_DECL_EXPORT __attribute__((visibility("default"))) 9 | #define SOME_INFER_DECL_IMPORT __attribute__((visibility("default"))) 10 | #endif 11 | 12 | #ifndef SOME_INFER_EXPORT 13 | #ifdef SOME_INFER_STATIC 14 | #define SOME_INFER_EXPORT 15 | #else 16 | #ifdef SOME_INFER_LIBRARY 17 | #define SOME_INFER_EXPORT SOME_INFER_DECL_EXPORT 18 | #else 19 | #define SOME_INFER_EXPORT SOME_INFER_DECL_IMPORT 20 | #endif 21 | #endif 22 | #endif 23 | 24 | #endif // SOMEGLOBAL_H 25 | -------------------------------------------------------------------------------- /src/libs/some-infer/include/some-infer/SomeModel.h: -------------------------------------------------------------------------------- 1 | #ifndef SOMEMODEL_H 2 | #define SOMEMODEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Some 11 | { 12 | class SomeModel { 13 | public: 14 | explicit SomeModel(const std::filesystem::path &modelPath, ExecutionProvider provider, int device_id); 15 | ~SomeModel(); 16 | 17 | bool is_open() const; 18 | // Forward pass through the model 19 | bool forward(const std::vector &waveform_data, std::vector ¬e_midi, 20 | std::vector ¬e_rest, std::vector ¬e_dur, std::string &msg); 21 | 22 | void terminate(); 23 | 24 | private: 25 | Ort::Env m_env; 26 | Ort::RunOptions run_options; 27 | Ort::SessionOptions m_session_options; 28 | Ort::Session m_session; 29 | Ort::AllocatorWithDefaultOptions m_allocator; 30 | const char *m_waveform_input_name; // Name of the waveform input 31 | const char *m_note_midi_output_name; // Name of the midi input 32 | const char *m_note_rest_output_name; // Name of the rest output 33 | const char *m_note_dur_output_name; // Name of the dur output 34 | 35 | #ifdef _WIN_X86 36 | Ort::MemoryInfo m_memory_info = Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU); 37 | #else 38 | Ort::MemoryInfo m_memory_info = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); 39 | #endif 40 | }; 41 | 42 | } // namespace Some 43 | 44 | #endif // SOMEMODEL_H 45 | -------------------------------------------------------------------------------- /src/libs/some-infer/some-inferConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/rmvpe-inferTargets.cmake") 4 | -------------------------------------------------------------------------------- /src/libs/some-infer/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(TestSome) 2 | 3 | file(GLOB_RECURSE _src *.h *.cpp) 4 | 5 | add_executable(${PROJECT_NAME} ${_src}) 6 | 7 | target_link_libraries(${PROJECT_NAME} PRIVATE 8 | some-infer::some-infer 9 | ) -------------------------------------------------------------------------------- /src/libs/some-infer/tests/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "wolf-midi/MidiFile.h" 10 | 11 | static void progressChanged(const int progress) { std::cout << "progress: " << progress << "%" << std::endl; } 12 | 13 | int main(int argc, char *argv[]) { 14 | if (argc != 7) { 15 | std::cerr << "Usage: " << argv[0] 16 | << " " << std::endl; 17 | return 1; 18 | } 19 | 20 | const std::filesystem::path modelPath = argv[1]; 21 | const std::filesystem::path wavPath = argv[2]; 22 | const std::string provider = argv[3]; 23 | const int device_id = std::stoi(argv[4]); 24 | const std::filesystem::path outMidiPath = argv[5]; 25 | const float tempo = std::stof(argv[6]); 26 | 27 | const auto someProvider = provider == "dml" ? Some::ExecutionProvider::DML : Some::ExecutionProvider::CPU; 28 | 29 | const Some::Some some(modelPath, someProvider, device_id); 30 | 31 | std::vector midis; 32 | std::string msg; 33 | 34 | bool success = some.get_midi(wavPath, midis, tempo, msg, progressChanged); 35 | 36 | if (success) { 37 | Midi::MidiFile midi; 38 | midi.setFileFormat(1); 39 | midi.setDivisionType(Midi::MidiFile::DivisionType::PPQ); 40 | midi.setResolution(480); 41 | 42 | midi.createTrack(); 43 | 44 | midi.createTimeSignatureEvent(0, 0, 4, 4); 45 | midi.createTempoEvent(0, 0, tempo); 46 | 47 | std::vector trackName; 48 | std::string str = "Some"; 49 | trackName.insert(trackName.end(), str.begin(), str.end()); 50 | 51 | midi.createTrack(); 52 | midi.createMetaEvent(1, 0, Midi::MidiEvent::MetaNumbers::TrackName, trackName); 53 | 54 | for (const auto &[note, start, duration] : midis) { 55 | midi.createNoteOnEvent(1, start, 0, note, 64); 56 | midi.createNoteOffEvent(1, start + duration, 0, note, 64); 57 | } 58 | 59 | midi.save(outMidiPath); 60 | } else { 61 | std::cerr << "Error: " << msg << std::endl; 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /src/tests/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openvpi/dataset-tools/f29318d938bf81779dceebf8a0b3e75cd7a08234/src/tests/CMakeLists.txt --------------------------------------------------------------------------------