This commit is contained in:
恍兮惚兮 2024-08-11 19:29:37 +08:00
parent f349289bf2
commit 4d2ac7bf10
6 changed files with 111 additions and 13 deletions

View File

@ -781,12 +781,13 @@ class loopbackrecorder:
if os.path.exists(filewav) == False:
callback("")
return
filemp3 = filewav.replace(".wav", ".mp3")
cmd = './files/plugins/shareddllproxy32.exe mainmp3 "{}" "{}"'.format(
filewav, filemp3
)
subproc_w(cmd, run=True)
if os.path.exists(filemp3):
with open(filewav, "rb") as ff:
wav = ff.read()
mp3 = winsharedutils.encodemp3(wav)
if mp3:
filemp3 = filewav[:-3] + "mp3"
with open(filemp3, "wb") as ff:
ff.write(mp3)
os.remove(filewav)
callback(filemp3)
else:

View File

@ -361,3 +361,18 @@ clipboard_callback.restype = HWND
clipboard_callback_stop = utilsdll.clipboard_callback_stop
clipboard_callback_stop.argtypes = (HWND,)
clipboard_callback_type = CFUNCTYPE(None, c_wchar_p, c_bool)
_encodemp3 = utilsdll.encodemp3
_encodemp3.argtypes = c_void_p, c_size_t, c_void_p
def encodemp3(wav):
ret = []
def cb(ptr, size):
ret.append(cast(ptr, POINTER(c_char))[:size])
_encodemp3(wav, len(wav), CFUNCTYPE(None, c_void_p, c_size_t)(cb))
if len(ret):
return ret[0]
return None

View File

@ -19,11 +19,10 @@ if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
target_link_libraries(shareddllproxy Mfplat mfuuid ${Detours})
set_target_properties(shareddllproxy PROPERTIES OUTPUT_NAME "shareddllproxy64")
else()
add_library(tinymp3 ../libs/tinymp3/shine_mp3.c)
add_subdirectory(voiceroid2)
add_library(x86lib eztrans.cpp dreye.cpp jbj7.cpp kingsoft.cpp le.cpp neospeech.cpp ../implsapi.cpp LR.cpp mp3.cpp)
add_library(x86lib eztrans.cpp dreye.cpp jbj7.cpp kingsoft.cpp le.cpp neospeech.cpp ../implsapi.cpp LR.cpp)
target_precompile_headers(voiceroid2 REUSE_FROM pch)
target_precompile_headers(x86lib REUSE_FROM pch)
target_link_libraries(shareddllproxy Mfplat mfuuid x86lib tinymp3 voiceroid2 ${Detours})
target_link_libraries(shareddllproxy Mfplat mfuuid x86lib voiceroid2 ${Detours})
set_target_properties(shareddllproxy PROPERTIES OUTPUT_NAME "shareddllproxy32")
endif()

View File

@ -5,7 +5,7 @@ int ntleaswmain(int argc, wchar_t *wargv[]);
int updatewmain(int argc, wchar_t *wargv[]);
bool checkisapatch();
#ifndef _WIN64
int mainmp3(int argc, wchar_t *argv[]);
// int mainmp3(int argc, wchar_t *argv[]);
int LRwmain(int argc, wchar_t *argv[]);
int jbjwmain(int argc, wchar_t *argv[]);
int dreyewmain(int argc, wchar_t *argv[]);
@ -65,7 +65,7 @@ int wmain(int argc, wchar_t *argv[])
{L"listpm", listprocessmodule},
{L"update", updatewmain},
#ifndef _WIN64
{L"mainmp3", mainmp3},
// {L"mainmp3", mainmp3},
{L"LR", LRwmain},
{L"le", lewmain},
{L"jbj7", jbjwmain},

View File

@ -10,9 +10,10 @@ generate_product_version(
VERSION_MINOR ${VERSION_MINOR}
VERSION_PATCH ${VERSION_PATCH}
)
add_library(winsharedutils MODULE webview2_extra.cpp AreoAcrylic.cpp screenshot.cpp ../implsapi.cpp hwnd.cpp globalmessagelistener.cpp theme.cpp version.cpp otsu.cpp clipboard.cpp lnk.cpp dllmain.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp ${versioninfo})
add_library(tinymp3 ../libs/tinymp3/shine_mp3.c)
add_library(winsharedutils MODULE mp3enc.cpp webview2_extra.cpp AreoAcrylic.cpp screenshot.cpp ../implsapi.cpp hwnd.cpp globalmessagelistener.cpp theme.cpp version.cpp otsu.cpp clipboard.cpp lnk.cpp dllmain.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp ${versioninfo})
target_precompile_headers(winsharedutils REUSE_FROM pch)
target_link_libraries(winsharedutils tinymp3)
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
set_target_properties(winsharedutils PROPERTIES OUTPUT_NAME "winsharedutils64")
else()

View File

@ -0,0 +1,82 @@
#include "define.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <timing.h>
#include <shine_mp3.h>
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"
int stereo = STEREO;
DECLARE void encodemp3(void *ptr, size_t size, void (*cb)(void *ptr, size_t size))
{
shine_config_t config;
shine_t s;
int written;
unsigned char *data;
/* Set the default MPEG encoding paramters - basically init the struct */
shine_set_config_mpeg_defaults(&config.mpeg);
config.mpeg.bitr = 320;
uint32_t sampleRate = 0;
uint64_t totalSampleCount = 0;
uint32_t channels = 0;
int16_t *data_in = drwav_open_memory_and_read_pcm_frames_s16(ptr, size, &channels, &sampleRate, &totalSampleCount, NULL);
if (data_in == NULL)
return;
totalSampleCount *= channels;
double startTime = now();
config.wave.samplerate = sampleRate;
config.wave.channels = (decltype(config.wave.channels))channels;
/* See if samplerate and bitrate are valid */
if (shine_check_config(config.wave.samplerate, config.mpeg.bitr) < 0)
return;
// printf("Unsupported samplerate/bitrate configuration.");
/* Set to stereo mode if wave data is stereo, mono otherwise. */
if (config.wave.channels > 1)
config.mpeg.mode = (decltype(config.mpeg.mode))stereo;
else
config.mpeg.mode = MONO;
/* Initiate encoder */
s = shine_initialise(&config);
int samples_per_pass = shine_samples_per_pass(s) * channels;
std::string sdata;
/* All the magic happens here */
size_t count = totalSampleCount / samples_per_pass;
int16_t *buffer = data_in;
for (int i = 0; i < count; i++)
{
data = shine_encode_buffer_interleaved(s, buffer, &written);
sdata += std::string((char *)data, written);
buffer += samples_per_pass;
}
size_t last = totalSampleCount % samples_per_pass;
if (last != 0)
{
int16_t *cache = (int16_t *)calloc(samples_per_pass, sizeof(int16_t));
if (cache != NULL)
{
memcpy(cache, buffer, last * sizeof(int16_t));
data = shine_encode_buffer_interleaved(s, cache, &written);
free(cache);
sdata += std::string((char *)data, written);
}
}
/* Flush and write remaining data. */
data = shine_flush(s, &written);
sdata += std::string((char *)data, written);
/* Close encoder. */
shine_close(s);
free(data_in);
double time_interval = calcElapsed(startTime, now());
cb(sdata.data(), sdata.size());
}