Skip to content

Commit

Permalink
Merge pull request #190 from solaoi/feature/refactoring_style
Browse files Browse the repository at this point in the history
Feature/refactoring style
  • Loading branch information
solaoi authored Jan 2, 2025
2 parents 9fb35a3 + 10a503f commit 0199d38
Show file tree
Hide file tree
Showing 37 changed files with 154 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tauri-build = { version = "1.5.5", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.8.1", features = ["api-all"] }
tauri = { version = "1.8.1", features = [ "macos-private-api", "api-all"] }
vosk = "0.2.0"
# cpal 0.15.3 has a bug that causes the app to crash on macOS with coreaudio-rs
cpal = "0.14.1"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/module/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl Action {
});

let post_body = json!({
"model": "gpt-4o-2024-08-06",
"model": "gpt-4o",
"temperature": temperature,
"messages": messages,
"response_format": response_format
Expand Down
15 changes: 11 additions & 4 deletions src-tauri/src/module/transcription_hybrid_online.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl TranscriptionHybridOnline {
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));

let mut messages: Vec<Value> = Vec::new();
let system_prompt = "あなたの役割は、ReazonSpeechとWhisperの出力を統合して「正確で読みやすい文字起こし」を作成することです。
let system_prompt = String::from("あなたの役割は、ReazonSpeechとWhisperの出力を統合して「正確で読みやすい文字起こし」を作成することです。
### 目的
- **正確性の確保**:発話内容を正確に伝えます。
Expand All @@ -125,12 +125,18 @@ impl TranscriptionHybridOnline {
- **文脈と推測の活用**:文脈から適切な言葉を推測し、誤認識を修正してください。
- **用語の一貫性**:同じ用語や表現は一貫して使用してください。
- **自然な日本語表現**:文法的に正しく、自然な日本語になるように修正してください。
- **途中で途切れた部分の明示**:発話の途中で始まったり、途中で終わっている場合は、「...」を挿入して途切れていることを明示してください。
") +
if !latest_speeches.is_empty() {"- **会話履歴の活用**:`history`(timestampとcontent)を必要に応じて参照し、誤認識の修正や表現の調整を行ってください。"}
else {""} + "
### 統合手順
1. **テキストの確定**
- ReazonSpeechの出力をベースに発話内容を確定します。
- 必要に応じてWhisperの出力や文脈を参考に、内容を補完します。
" +
if !latest_speeches.is_empty() {" - 必要に応じてWhisperの出力や文脈(`history`)を参考に、内容を補完します。"}
else {" - 必要に応じてWhisperの出力を参考に、内容を補完します。"} + "
2. **誤認識の修正**
- 文脈や一般知識を活用し、誤った表現を正しく修正します。特に専門用語や固有名詞に注意してください。
Expand All @@ -140,6 +146,7 @@ impl TranscriptionHybridOnline {
4. **表現の調整**
- 冗長な表現を避け、自然で簡潔な文章に整えます。
- 途中から始まっている発話や、途中で終わっている発話があれば「...」を挿入して、発言の断片を示します。
5. **最終チェック**
- 全体を見直し、一貫性と正確さ、自然な流れを確認します。
Expand All @@ -150,7 +157,7 @@ impl TranscriptionHybridOnline {
{
\"integrated_transcription\": \"統合された文字起こし結果をここに挿入\"
}
```".to_string();
```";

messages.push(json!({
"role": "system",
Expand Down Expand Up @@ -186,7 +193,7 @@ impl TranscriptionHybridOnline {
});

let post_body = json!({
"model": "gpt-4o-2024-08-06",
"model": "gpt-4o",
"temperature": temperature,
"messages": messages,
"response_format": response_format
Expand Down
14 changes: 10 additions & 4 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"protocol": {
"asset": true,
"assetScope": [ "**" ]
},
"window": {
"all": true
}
},
"bundle": {
Expand Down Expand Up @@ -52,21 +55,24 @@
}
},
"security": {
"csp": "default-src 'self'; img-src 'self' data: asset: https://asset.localhost; media-src blob: stream: https://stream.localhost asset: https://asset.localhost; style-src 'self' 'unsafe-inline'"
"csp": "default-src 'self'; img-src 'self' data: http: https: asset: https://asset.localhost; media-src blob: stream: https://stream.localhost asset: https://asset.localhost; style-src 'self' 'unsafe-inline'"
},
"updater": {
"active": false
},
"windows": [
{
"transparent": true,
"decorations": false,
"acceptFirstMouse": true,
"fullscreen": false,
"width": 1180,
"height": 768,
"minWidth": 1180,
"minHeight": 384,
"resizable": true,
"title": "Lycoris"
"resizable": true
}
]
],
"macOSPrivateApi": true
}
}
Binary file added src/assets/macos/Close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/macos/Minimize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/macos/Zoom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 3 additions & 15 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
import { useRecoilValue, useSetRecoilState } from "recoil"
import { getVersion } from '@tauri-apps/api/app';
import { featureState } from "../store/atoms/featureState"
import { selectedNoteState } from "../store/atoms/selectedNoteState"
import { AudioDevices } from "./molecules/AudioDevice"
import { SpeakerLanguage } from "./molecules/SpeakerLanguage"
import { TranscriptionAccuracy } from "./molecules/TranscriptionAccuracy"
import { useEffect, useState } from "react";
import { SmartVoice } from "./molecules/SmartVoice";
import { modelStyleBertVits2DownloadedState } from "../store/atoms/modelStyleBertVits2DownloadedState";
import { MacosControls } from "./molecules/MacosControls";

const Header = (): JSX.Element => {
const setFeature = useSetRecoilState(featureState)
const setSelectedNote = useSetRecoilState(selectedNoteState);
const [appVersion, setAppVersion] = useState<string | null>(null);
useEffect(() => {
const fetchVersion = async () => {
const version = await getVersion();
setAppVersion(version);
};
fetchVersion();
}, []);

const downloadedBaseModels = useRecoilValue(modelStyleBertVits2DownloadedState);
const is_base_downloaded = downloadedBaseModels.filter(m => m === "style-bert-vits2").length > 0

return (
<header className="sticky top-0 z-10" style={{ minWidth: "770px", height: "64px" }}>
<div className="navbar bg-base-200">
<div className="flex flex-1 items-baseline select-none">
<div className="flex flex-col items-end">
<a className="ml-2 font-bold text-xl text-primary" href="https://github.com/solaoi/lycoris" target="_blank">Lycoris</a>
<p className="text-xs text-slate-500 cursor-default">v{appVersion}</p>
</div>
<div data-tauri-drag-region className="flex flex-1 select-none items-start" style={{ height: "calc(64px - 1rem)" }}>
<MacosControls />
</div>
<div className="flex-none mr-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" className="size-5">
Expand Down
23 changes: 15 additions & 8 deletions src/components/SideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ const SideMenu = (): JSX.Element => {
invoke('delete_note_command', { noteId: note_id });
}
return (
<div className="flex justify-between border-r" style={{ width: "320px", flexFlow: "column", height: `calc(100vh - 64px)` }}>
<div className="flex justify-between border-r bg-base-100" style={{ width: "320px", flexFlow: "column", height: `calc(100vh - 64px)` }}>
<div className="flex" style={{ flexFlow: "column" }}>
<div className="bg-white flex items-center justify-center select-none text-xl" style={{ height: "64px" }}>
<input type="text" placeholder="タイトル検索..." className="input input-bordered focus:outline-none" value={searchWord} onChange={e => setSearchWord(e.target.value)} />
<button type="button" className="bg-base-200 hover:bg-base-300 focus:outline-none rounded-lg px-5 m-1"
style={{ height: "48px" }}
<div className="bg-base-100 flex items-center justify-center select-none text-xl h-[48px]">
<button type="button" className="bg-base-200 hover:bg-base-300 focus:outline-none rounded-lg px-2 py-1"
onClick={() => {
setNotes(prev => {
const today = new Date();
Expand All @@ -70,12 +68,21 @@ const SideMenu = (): JSX.Element => {
});
}}
>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m3.75 9v6m3-3H9m1.5-12H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" />
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" className="size-5">
<path d="m5.433 13.917 1.262-3.155A4 4 0 0 1 7.58 9.42l6.92-6.918a2.121 2.121 0 0 1 3 3l-6.92 6.918c-.383.383-.84.685-1.343.886l-3.154 1.262a.5.5 0 0 1-.65-.65Z" />
<path d="M3.5 5.75c0-.69.56-1.25 1.25-1.25H10A.75.75 0 0 0 10 3H4.75A2.75 2.75 0 0 0 2 5.75v9.5A2.75 2.75 0 0 0 4.75 18h9.5A2.75 2.75 0 0 0 17 15.25V10a.75.75 0 0 0-1.5 0v5.25c0 .69-.56 1.25-1.25 1.25h-9.5c-.69 0-1.25-.56-1.25-1.25v-9.5Z" />
</svg>
</button>
<div className="relative ml-2">
<input id="title-search" type="text" placeholder="タイトル検索..." className="input input-bordered focus:outline-none h-8" value={searchWord} onChange={e => setSearchWord(e.target.value)} />
<label htmlFor="title-search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" className="size-6 absolute top-1 right-2">
<path fillRule="evenodd" d="M9 3.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11ZM2 9a7 7 0 1 1 12.452 4.391l3.328 3.329a.75.75 0 1 1-1.06 1.06l-3.329-3.328A7 7 0 0 1 2 9Z" clipRule="evenodd" />
</svg>
</label>
</div>
</div>
<div className="overflow-auto" style={{ height: `calc(100vh - 128px)` }} >
<div className="overflow-auto" style={{ height: `calc(100vh - 112px)` }} >
<div ref={targetRef} />
{notes.filter(note => {
if (searchWord === "") {
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/AudioDevice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const AudioDevices = (): JSX.Element => {
}

return (
<div className="dropdown">
<div className="dropdown select-none">
{isRecording ? <label tabIndex={0} className="group normal-case btn w-52 flex justify-between btn-disabled" style={{ color: "inherit", backgroundColor: "hsl(var(--b1) / var(--tw-bg-opacity))", border: "1px solid hsl(var(--bc) / 0.2)" }}>
<div className="w-36 text-left overflow-x-hidden whitespace-nowrap text-ellipsis">{validAudioDevice(hasDesktopAudio, audioDevice)}</div>
<div>
Expand Down
17 changes: 17 additions & 0 deletions src/components/molecules/MacosControls.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { appWindow } from "@tauri-apps/api/window"

import closeIcon from "../../assets/macos/Close.png"
import minimizeIcon from "../../assets/macos/Minimize.png"
import zoomIcon from "../../assets/macos/Zoom.png"

const MacosControls = (): JSX.Element => {
return (
<div className="flex p-[4px]">
<img src={closeIcon} width={12} height={12} className="mr-[8px]" onClick={async () => await appWindow.close()} />
<img src={minimizeIcon} width={12} height={12} className="mr-[8px]" onClick={async () => await appWindow.minimize()} />
<img src={zoomIcon} width={12} height={12} onClick={async () => await appWindow.toggleMaximize()} />
</div>
)
}

export { MacosControls }
2 changes: 1 addition & 1 deletion src/components/molecules/ModelDownloadFugumtEnJaButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ModelDownloadFugumtEnJaButton = (): JSX.Element => {
const is_base_downloaded = downloadedBaseModels.filter(m => m === "large").length > 0

return (
<button className="btn gap-2 glass border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading || !is_base_downloaded}>
<button className="btn gap-2 bg-base-100 border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading || !is_base_downloaded}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M9 12.75l3 3m0 0l3-3m-3 3v-7.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/ModelDownloadFugumtJaEnButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ModelDownloadFugumtJaEnButton = (): JSX.Element => {
const is_base_downloaded = downloadedBaseModels.filter(m => m === "large").length > 0

return (
<button className="btn gap-2 glass border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading || !is_base_downloaded}>
<button className="btn gap-2 bg-base-100 border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading || !is_base_downloaded}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M9 12.75l3 3m0 0l3-3m-3 3v-7.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/ModelDownloadHonyaku13BButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ModelDownloadHonyaku13BButton = (): JSX.Element => {
const is_base_downloaded = downloadedBaseModels.filter(m => m === "large").length > 0

return (
<button className="btn gap-2 glass border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading || !is_base_downloaded}>
<button className="btn gap-2 bg-base-100 border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading || !is_base_downloaded}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M9 12.75l3 3m0 0l3-3m-3 3v-7.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ModelDownloadReazonSpeechButton = (): JSX.Element => {
const is_downloading = downloadingModels.filter(m => m === modelType).length > 0

return (
<button className="btn gap-2 glass border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading}>
<button className="btn gap-2 bg-base-100 border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M9 12.75l3 3m0 0l3-3m-3 3v-7.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ModelDownloadStyleBertVits2Button = (): JSX.Element => {
const is_downloading = downloadingModels.filter(m => m === modelType).length > 0

return (
<button className="btn gap-2 glass border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading}>
<button className="btn gap-2 bg-base-100 border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M9 12.75l3 3m0 0l3-3m-3 3v-7.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ModelDownloadStyleBertVits2VoiceButton = (props: Props): JSX.Element => {
const is_base_downloaded = downloadedBaseModels.filter(m => m === "style-bert-vits2").length > 0

return (
<button className="btn glass border border-solid border-neutral-300 gap-2 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading || !is_base_downloaded}>
<button className="btn bg-base-100 border border-solid border-neutral-300 gap-2 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading || !is_base_downloaded}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M9 12.75l3 3m0 0l3-3m-3 3v-7.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/ModelDownloadVoskButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ModelDownloadVoskButton = (props: Props): JSX.Element => {
const is_downloading = downloadingModels.filter(m => m === modelType).length > 0

return (
<button className="btn gap-2 glass border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading}>
<button className="btn gap-2 bg-base-100 border border-solid border-neutral-300 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M9 12.75l3 3m0 0l3-3m-3 3v-7.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/ModelDownloadWhisperButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ModelDownloadWhisperButton = (props: Props): JSX.Element => {
const is_downloading = downloadingModels.filter(m => m === modelType).length > 0

return (
<button className="btn glass border border-solid border-neutral-300 gap-2 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading}>
<button className="btn bg-base-100 border border-solid border-neutral-300 gap-2 text-secondary select-none" onClick={click} disabled={is_downloaded || is_downloading}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M9 12.75l3 3m0 0l3-3m-3 3v-7.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
Expand Down
5 changes: 3 additions & 2 deletions src/components/molecules/MyMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import { Download } from '../atoms/Download';
type MyMarkdownProps = {
content: string
title?: string
minWidth?: string
}

const MyMarkdown = (props: MyMarkdownProps) => {
const { content, title = Date.now() } = props
const { content, title = Date.now(), minWidth } = props
const rootRef = useRef<HTMLDivElement>(null);

const [isOpen, setOpen] = useState(false);
Expand Down Expand Up @@ -146,7 +147,7 @@ const MyMarkdown = (props: MyMarkdownProps) => {
}, [content]);

return (
<div ref={rootRef} className='znc w-full'>
<div ref={rootRef} className='znc w-full' style={minWidth ? { minWidth } : {}}>
<Markdown
options={{
forceBlock: true,
Expand Down
Loading

0 comments on commit 0199d38

Please sign in to comment.