> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# ReactでAudio Nativeを使用

> **Info**
>
> このガイドを続ける前に、[Audio Nativeの概要](/docs/ja/eleven-creative/audio-tools/audio-native)の手順に従って、
> Audio Nativeを使い始めてください。

このガイドでは、Audio NativeをReactアプリに統合する方法を紹介します。Next.jsプロジェクトを中心に説明しますが、基本的な考え方はReactベースのあらゆるアプリケーションに適用できます。

#### Audio NativeのReactコンポーネントを作成する

[Audio Nativeの概要](/docs/ja/eleven-creative/audio-tools/audio-native)の手順を完了すると、埋め込みコードのスニペットが表示されます。以下はその例です。

**`Embed code snippet`**

```html title="Embed code snippet"
  <div
    id="elevenlabs-audionative-widget"
    data-height="90"
    data-width="100%"
    data-frameborder="no"
    data-scrolling="no"
    data-publicuserid="public-user-id"
    data-playerurl="https://elevenlabs.io/player/index.html"
    data-projectid="project-id"
  >
    Loading the <a href="https://elevenlabs.io/text-to-speech" target="_blank" rel="noopener">Elevenlabs Text to Speech</a> AudioNative Player...
  </div>
  <script src="https://elevenlabs.io/player/audioNativeHelper.js" type="text/javascript"></script>
```

スニペットからデータを抽出して、カスタマイズ可能なReactコンポーネントを作成できます。

**`ElevenLabsAudioNative.tsx`**

```tsx title="ElevenLabsAudioNative.tsx" maxLines=0
// ElevenLabsAudioNative.tsx

'use client';

import { useEffect } from 'react';

export type ElevenLabsProps = {
  publicUserId: string;
  textColorRgba?: string;
  backgroundColorRgba?: string;
  size?: 'small' | 'large';
  children?: React.ReactNode;
};

export const ElevenLabsAudioNative = ({
  publicUserId,
  size,
  textColorRgba,
  backgroundColorRgba,
  children,
}: ElevenLabsProps) => {
  useEffect(() => {
    const script = document.createElement('script');

    script.src = 'https://elevenlabs.io/player/audioNativeHelper.js';
    script.async = true;
    document.body.appendChild(script);

    return () => {
      document.body.removeChild(script);
    };
  }, []);

  return (
    <div
      id="elevenlabs-audionative-widget"
      data-height={size === 'small' ? '90' : '120'}
      data-width="100%"
      data-frameborder="no"
      data-scrolling="no"
      data-publicuserid={publicUserId}
      data-playerurl="https://elevenlabs.io/player/index.html"
      data-small={size === 'small' ? 'True' : 'False'}
      data-textcolor={textColorRgba ?? 'rgba(0, 0, 0, 1.0)'}
      data-backgroundcolor={backgroundColorRgba ?? 'rgba(255, 255, 255, 1.0)'}
    >
      {children ? children : 'Elevenlabs AudioNative Player'}
    </div>
  );
};

export default ElevenLabsAudioNative;
```

上記のコンポーネントは[GitHub](https://github.com/elevenlabs/examples/blob/main/examples/audio-native/react/ElevenLabsAudioNative.tsx)で確認できます。

#### Audio Nativeコンポーネントを使用する

ページでコンポーネントを使用する前に、元のコードスニペットからパブリックユーザーIDを取得する必要があります。埋め込みコードスニペットの`data-publicuserid`の内容をコピーし、コンポーネントの`publicUserId`プロパティに入力してください。

**`page.tsx`**

```tsx title="page.tsx" maxLines=0
import { ElevenLabsAudioNative } from './path/to/ElevenLabsAudioNative';

export default function Page() {
  return (
    <div>
      <h1>Your Page Title</h1>

      // Insert the public user ID from the embed code snippet
      <ElevenLabsAudioNative publicUserId="<your-public-user-id>" />

      <p>Your page content...</p>
    </div>
  );
}
```

#### コンポーネントプロパティでプレーヤーをカスタマイズする

コンポーネントプロパティを使ってプレーヤーをカスタマイズできます。たとえば、サイズ、テキストの色、背景色を変更できます。

**`page.tsx`**

```tsx title="page.tsx" maxLines=0
import { ElevenLabsAudioNative } from './path/to/ElevenLabsAudioNative';

export default function Page() {
  return (
    <div>
      <h1>Your Page Title</h1>

      <ElevenLabsAudioNative
        publicUserId="<your-public-user-id>"
        size="small"
        textColorRgba="rgba(255, 255, 255, 1.0)"
        backgroundColorRgba="rgba(0, 0, 0, 1.0)"
      />

      <p>Your page content...</p>
    </div>
  );
}
```