Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

音声の周波数データを取得する不要なコードを削除 #45

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions frontend/src/app/voice-chat/_components/VoiceChatForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,6 @@
}
};

const setupAudioVisualization = (stream: MediaStream) => {
const audioContext = new AudioContext();
const source = audioContext.createMediaStreamSource(stream);
const analyser = audioContext.createAnalyser();
analyser.fftSize = 256;
source.connect(analyser);

const bufferLength = analyser.frequencyBinCount;
const dataArray = new Uint8Array(bufferLength);

const updateIndicator = () => {
analyser.getByteFrequencyData(dataArray);
requestAnimationFrame(updateIndicator);
};
updateIndicator();
};

let newResponseMessage = '';

// Handle incoming messages from the data channel
Expand Down Expand Up @@ -324,12 +307,19 @@

const startSession = async () => {
try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
setupAudioVisualization(stream);
const stream = await navigator.mediaDevices.getUserMedia(
{
audio: {
channelCount: 1,
sampleRate: 16000,
},
},
);

// 音声トラックの参照を保持し、初期状態を設定
audioTrackRef.current = stream.getTracks()[0];
audioTrackRef.current.enabled = !isMicMuted; // 初期状態をisMicMutedの逆に設定
// 初期状態をisMicMutedの逆に設定
audioTrackRef.current.enabled = !isMicMuted;

const ephemeralToken = await createEphemeralToken();

Expand All @@ -348,6 +338,27 @@

dataChannel.onopen = () => {
setIsDataChannelReady(true);
// 自動的に「こんにちは」メッセージを送信
const message = {
type: 'conversation.item.create',
item: {
type: 'message',
role: 'user',
content: [
{
type: 'input_text',
text: 'こんにちは',
},
],
},
};

const response = {
type: 'response.create',
};

dataChannel.send(JSON.stringify(message));
dataChannel.send(JSON.stringify(response));
};

dataChannel.onclose = () => {
Expand Down Expand Up @@ -523,7 +534,7 @@
if (conversation.role === 'user') {
return (
<MessageCard
key={index}

Check warning on line 537 in frontend/src/app/voice-chat/_components/VoiceChatForm.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

Do not use Array index as 'key'

Check warning on line 537 in frontend/src/app/voice-chat/_components/VoiceChatForm.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

Do not use Array index as 'key'
message={conversation.message}
showFeedback={false}
/>
Expand All @@ -532,7 +543,7 @@

return (
<MessageCard
key={index}

Check warning on line 546 in frontend/src/app/voice-chat/_components/VoiceChatForm.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

Do not use Array index as 'key'

Check warning on line 546 in frontend/src/app/voice-chat/_components/VoiceChatForm.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

Do not use Array index as 'key'
avatar="/omochi.png"
message={conversation.message}
/>
Expand Down
Loading