Skip to content

Commit

Permalink
Amivoiceのログ保存設定を反映
Browse files Browse the repository at this point in the history
  • Loading branch information
solaoi committed Aug 25, 2024
1 parent 12da754 commit 8229c20
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src-tauri/migrations/001.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ VALUES("settingModel", "gpt-4o-mini");
INSERT INTO settings(setting_name, setting_status)
VALUES("settingAmiVoiceModel", "general");
INSERT INTO settings(setting_name, setting_status)
VALUES("settingAmiVoiceLogging", "off");
INSERT INTO settings(setting_name, setting_status)
VALUES("settingAILanguage", "None");
INSERT INTO settings(setting_name, setting_status)
VALUES(
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/module/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ impl Sqlite {
);
}

pub fn select_amivoice_logging(&self) -> Result<String, rusqlite::Error> {
return self.conn.query_row(
"SELECT setting_status FROM settings WHERE setting_name = \"settingAmiVoiceLogging\"",
params![],
|row| Ok(row.get_unwrap(0)),
);
}

pub fn select_ai_resource(&self) -> Result<String, rusqlite::Error> {
return self.conn.query_row(
"SELECT setting_status FROM settings WHERE setting_name = \"settingResource\"",
Expand Down
17 changes: 15 additions & 2 deletions src-tauri/src/module/transcription_amivoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@ pub struct TranscriptionAmivoice {
note_id: u64,
token: String,
model: String,
logging: String,
}

impl TranscriptionAmivoice {
pub fn new(app_handle: AppHandle, note_id: u64) -> Self {
let sqlite = Sqlite::new();
let token = sqlite.select_amivoice_token().unwrap();
let model = sqlite.select_amivoice_model().unwrap();
let logging = sqlite.select_amivoice_logging().unwrap();
Self {
app_handle,
sqlite,
note_id,
token,
model,
logging,
}
}

Expand Down Expand Up @@ -71,8 +74,13 @@ impl TranscriptionAmivoice {
file_path: String,
token: String,
model: String,
logging: String,
) -> Result<String, Box<dyn std::error::Error>> {
let url = "https://acp-api.amivoice.com/v1/nolog/recognize";
let url = if logging == "on" {
"https://acp-api.amivoice.com/v1/recognize"
} else {
"https://acp-api.amivoice.com/v1/nolog/recognize"
};
let client = Client::new();

let mut file = File::open(file_path).await?;
Expand Down Expand Up @@ -151,7 +159,12 @@ impl TranscriptionAmivoice {
fn convert(&mut self) -> Result<(), rusqlite::Error> {
let vosk_speech = self.sqlite.select_vosk(self.note_id);
return vosk_speech.and_then(|speech| {
let result = Self::request(speech.wav, self.token.clone(), self.model.clone());
let result = Self::request(
speech.wav,
self.token.clone(),
self.model.clone(),
self.logging.clone(),
);

if result.is_ok() {
let updated = self
Expand Down
36 changes: 36 additions & 0 deletions src/components/molecules/SettingAmiVoiceLogging.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ChangeEvent } from "react";
import { useRecoilState } from 'recoil';
import { settingKeyState } from "../../store/atoms/settingKeyState";

const SettingAmiVoiceLogging = (): JSX.Element => {
const settingLoggings = ["on", "off"] as const;
const modelNameMapper = (model: typeof settingLoggings[number])=>{
switch(model){
case "on":
return "有効"
case "off":
return "無効"
}
}
const [settingKey, setSettingKey] = useRecoilState(settingKeyState("settingAmiVoiceLogging"))

const change = (e: ChangeEvent<HTMLSelectElement>) => {
const settingKey = e.target.value
setSettingKey(settingKey)
}

return (
<div className="flex items-center mb-2">
<p className="w-[12rem]">ログ保存</p>
<div className="flex flex-col w-full">
<select className="select select-bordered focus:outline-none text-xs w-fit" name="setting-amivoice-logging" onChange={change} >
{settingLoggings?.map((logging, i) => (
<option key={"setting-logging" + i} value={logging} selected={logging === settingKey}>{modelNameMapper(logging)}</option>
))}
</select>
</div>
</div>
)
}

export { SettingAmiVoiceLogging }
6 changes: 5 additions & 1 deletion src/components/organisms/SettingsMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ModelDownloadHonyaku13BButton } from "../molecules/ModelDownloadHonyaku
import { ModelDownloadHonyaku13BProgress } from "../molecules/ModelDownloadHonyaku13BProgress"
import { SettingProcesses } from "../molecules/SettingProcesses"
import { SettingOnlines } from "../molecules/SettingOnlines"
import { SettingAmiVoiceLogging } from "../molecules/SettingAmiVoiceLogging"

const SettingsMain = (): JSX.Element => {
const settingLanguage = useRecoilValue(settingLanguageState);
Expand Down Expand Up @@ -622,7 +623,10 @@ const SettingsMain = (): JSX.Element => {
<div className="mb-8">
<SettingKey settingName="settingKeyAmivoice" />
</div>
<SettingAmiVoiceModel />
<div className="mb-8">
<SettingAmiVoiceModel />
</div>
<SettingAmiVoiceLogging />
</>}
</div>
</div>
Expand Down

0 comments on commit 8229c20

Please sign in to comment.