aisearch-openai-rag-audio

Azure-SamplesMIT活跃维护

基于 Azure AI Search 和 gpt-4o-realtime 的语音 RAG 示例,让语音助手能实时检索知识库并生成带依据的对话回答。

A simple example implementation of the VoiceRAG pattern to power interactive voice generative AI experiences using RAG with Azure AI Search and Azure OpenAI's gpt-4o-realtime-preview model.

暂无版本566star +1 / 7 天357fork同步于 2026-11-10 17:58 UTC

怎么上手

由 README 提炼,执行前请确认
azd auth login
azd env new
azd up
硬件要求按 README 说明

README 未说明本地显存或 GPU 要求,模型推理全部在 Azure OpenAI 服务端完成;本地只需能运行 Python 后端与浏览器,或直接用 GitHub Codespaces / Dev Containers。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用 Azure AI Search 检索、GPT-4o 实时语音 API 对话的 VoiceRAG 示例应用

基于 Azure AI Search 和 gpt-4o-realtime 的语音 RAG 示例,让语音助手能实时检索知识库并生成带依据的对话回答。

核心能力

  • 浏览器麦克风采集语音,交给 GPT-4o Realtime API 处理
  • 用 Azure AI Search 检索知识库并注入实时语音对话
  • 把模型回复以音频形式在浏览器中播放
  • 展示生成回答所引用的搜索结果
  • 含 Bicep 基础设施与 Dockerfile,可部署到 Azure Container Apps

容易踩的坑

需先具备可用的 Azure AI Search 与 Azure OpenAI(gpt-4o-realtime-preview)资源,否则本地跑不起来;azd up 会立即产生费用,主要来自 AI Search,不用时记得 azd down;本地开发需 Python >=3.11 且 python 与 pip 在 PATH 中,Windows 还需 PowerShell;不用 azd up 时须手写 app/backend/.env 配置各端点与密钥。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    VoiceRAG: An Application Pattern for RAG + Voice Using Azure AI Search and the GPT-4o Realtime API for Audio

    Open in GitHub Codespaces Open in Dev Containers

    This repo contains an example of how to implement RAG support in applications that use voice as their user interface, powered by the GPT-4o realtime API for audio. We describe the pattern in more detail in this blog post, and you can see this sample app in action in this short video.

    Features

    • Voice interface: The app uses the browser's microphone to capture voice input, and sends it to the backend where it is processed by the Azure OpenAI GPT-4o Realtime API.
    • RAG (Retrieval Augmented Generation): The app uses the Azure AI Search service to answer questions about a knowledge base, and sends the retrieved documents to the GPT-4o Realtime API to generate a response.
    • Audio output: The app plays the response from the GPT-4o Realtime API as audio, using the browser's audio capabilities.
    • Citations: The app shows the search results that were used to generate the response.

    Architecture Diagram

    The RTClient in the frontend receives the audio input, sends that to the Python backend which uses an RTMiddleTier object to interface with the Azure OpenAI real-time API, and includes a tool for searching Azure AI Search.

    Diagram of real-time RAG pattern

    This repository includes infrastructure as code and a Dockerfile to deploy the app to Azure Container Apps, but it can also be run locally as long as Azure AI Search and Azure OpenAI services are configured.

    Getting Started

    You have a few options for getting started with this template. The quickest way to get started is GitHub Codespaces, since it will setup all the tools for you, but you can also set it up locally. You can also use a VS Code dev container

    GitHub Codespaces

    You can run this repo virtually by using GitHub Codespaces, which will open a web-based VS Code in your browser:

    Open in GitHub Codespaces

    Once the codespace opens (this may take several minutes), open a new terminal and proceed to deploy the app.

    VS Code Dev Containers

    You can run the project in your local VS Code Dev Container using the Dev Containers extension:

    1. Start Docker Desktop (install it if not already installed)

    2. Open the project:

      Open in Dev Containers

    3. In the VS Code window that opens, once the project files show up (this may take several minutes), open a new terminal, and proceed to deploying the app.

    Local environment

    1. Install the required tools:

      • Azure Developer CLI
      • Node.js
      • Python >=3.11
        • Important: Python and the pip package manager must be in the path in Windows for the setup scripts to work.
        • Important: Ensure you can run python --version from console. On Ubuntu, you might need to run sudo apt install python-is-python3 to link python to python3.
      • Git
      • Powershell - For Windows users only.
    2. Clone the repo (git clone https://github.com/Azure-Samples/aisearch-openai-rag-audio)

    3. Proceed to the next section to deploy the app.

    Deploying the app

    The steps below will provision Azure resources and deploy the application code to Azure Container Apps.

    1. Login to your Azure account:

      azd auth login
      

      For GitHub Codespaces users, if the previous command fails, try:

       azd auth login --use-device-code
      
    2. Create a new azd environment:

      azd env new
      

      Enter a name that will be used for the resource group. This will create a new folder in the .azure folder, and set it as the active environment for any calls to azd going forward.

    3. (Optional) This is the point where you can customize the deployment by setting azd environment variables, in order to use existing services or customize the voice choice.

    4. Run this single command to provision the resources, deploy the code, and setup integrated vectorization for the sample data:

      azd up
      
      • Important: Beware that the resources created by this command will incur immediate costs, primarily from the AI Search resource. These resources may accrue costs even if you interrupt the command before it is fully executed. You can run azd down or delete the resources manually to avoid unnecessary spending.
      • You will be prompted to select two locations, one for the majority of resources and one for the OpenAI resource, which is currently a short list. That location list is based on the OpenAI model availability table and may become outdated as availability changes.
    5. After the application has been successfully deployed you will see a URL printed to the console. Navigate to that URL to interact with the app in your browser. To try out the app, click the "Start conversation button", say "Hello", and then ask a question about your data like "What is the whistleblower policy for Contoso electronics?" You can also now run the app locally by following the instructions in the next section.

    Development server

    You can run this app locally using either the Azure services you provisioned by following the deployment instructions, or by pointing the local app at already existing services.

    1. If you deployed with azd up, you should see a app/backend/.env file with the necessary environment variables.

    2. If did not use azd up, you will need to create app/backend/.env file with the following environment variables:

      AZURE_OPENAI_ENDPOINT=wss://<your instance name>.openai.azure.com
      AZURE_OPENAI_REALTIME_DEPLOYMENT=gpt-4o-realtime-preview
      AZURE_OPENAI_REALTIME_VOICE_CHOICE=<choose one: echo, alloy, shimmer>
      AZURE_OPENAI_API_KEY=<your api key>
      AZURE_SEARCH_ENDPOINT=https://<your service name>.search.windows.net
      AZURE_SEARCH_INDEX=<your index name>
      AZURE_SEARCH_API_KEY=<your api key>
      

      To use Entra ID (your user when running locally, managed identity when deployed) simply don't set the keys.

    3. Run this command to start the app:

      Windows:

      pwsh .\scripts\start.ps1
      

      Linux/Mac:

      ./scripts/start.sh
      
    4. The app is available on http://localhost:8765.

      Once the app is running, when you navigate to the URL above you should see the start screen of the app: app screenshot

      To try out the app, click the "Start conversation button", say "Hello", and then ask a question about your data like "What is the whistleblower policy for Contoso electronics?"

    Guidance

    Costs

    Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage. However, you can try the Azure pricing calculator for the resources below.

    • Azure Container Apps: Consumption plan with 1 CPU core, 2.0 GB RAM. Pricing with Pay-as-You-Go. Pricing
    • Azure OpenAI: Standard tier, gpt-4o-realtime and text-embedding-3-large models. Pricing per 1K tokens used. Pricing
    • Azure AI Search: Standard tier, 1 replica, free level of semantic search. Pricing per hour. Pricing
    • Azure Blob Storage: Standard tier with ZRS (Zone-redundant storage). Pricing per storage and read operations. Pricing
    • Azure Monitor: Pay-as-you-go tier. Costs based on data ingested. Pricing

    To reduce costs, you can switch to free SKUs for various services, but those SKUs have limitations.

    ⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use, either by deleting the resource group in the Portal or running azd down.

    Security

    This template uses Managed Identity to eliminate the need for developers to manage these credentials. Applications can use managed identities to obtain Microsoft Entra tokens without having to manage any credentials.To ensure best practices in your repo we recommend anyone creating solutions based on our templates ensure that the Github secret scanning setting is enabled in your repos.

    Notes

    Sample data: The PDF documents used in this demo contain information generated using a language model (Azure OpenAI Service). The information contained in these documents is only for demonstration purposes and does not reflect the opinions or beliefs of Microsoft. Microsoft makes no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information contained in this document. All rights reserved to Microsoft.

    Resources

    Getting help

    This is a sample built to demonstrate the capabilities of modern Generative AI apps and how they can be built in Azure. For help with deploying this sample, please post in GitHub Issues. If you're a Microsoft employee, you can also post in our Teams channel.

    This repository is supported by the maintainers, not by Microsoft Support, so please use the support mechanisms described above, and we will do our best to help you out.

    For general questions about developing AI solutions on Azure, join the Azure AI Foundry Developer Community:

    Azure AI Foundry Discord Azure AI Foundry Developer Forum