Azure Services

Two Azure services are integrated: OpenAI for LLM form filling and Speech to Text for transcription. - Called via wrappers in src/lib/ - All calls are proxied through Supabase Edge Functions for security. - Never call directly from screens.


Azure OpenAI (src/lib/azureOpenAI.ts)

Usage

import { azureOpenAIService } from '@/src/lib/azureOpenAI';

const response = await azureOpenAIService.chat("Hello!", "You are a helpful assistant.");

Or for more control:

const response = await azureOpenAIService.sendMessage(
  [{ role: 'user', content: 'Extract data...' }], 
  { temperature: 0.3, maxTokens: 800 }
);

Session Summarization

Called from src/services/recordingService.ts after transcription completes.

export async function summarizeTranscription(transcription: string): Promise<string> {
  return azureOpenAIService.sendMessage([
    {
      role: 'system',
      content:
        'You are an assistant for social workers. Summarize the session into: ' +
        'main concerns, agreed actions, and risk indicators. Use clinical language.',
    },
    { role: 'user', content: transcription },
  ], { temperature: 0.3, maxTokens: 800 });
}

Options Reference

Option Recommended Notes
temperature 0.1-0.3 Lower for structured extraction, higher for narrative
maxTokens 400-1000 Set per use case

Azure Speech-to-Text (src/lib/azureSpeech.ts)

Usage

import { azureSpeechService } from '@/src/lib/azureSpeech';

// Note: storagePath is the path to the audio file in Supabase Storage
const transcription = await azureSpeechService.transcribeAudio(storagePath, "en-US");

Implementation Details

The azureSpeechService proxies calls through the azure-speech Supabase Edge Function. - The app uploads the audio to Supabase Storage first. - It then passes the storagePath to the Edge Function. - The Edge Function retrieves the audio from storage, makes the request to Azure, and returns the transcription. - Supports speaker diarization (Speaker 1, Speaker 2, etc.).

Supported Languages

Use azureSpeechService.getSupportedLanguages() to get the list of supported locales (e.g., en-US, es-MX, fr-FR).


Security Model (Proxy Pattern)

For security, Azure API keys never ship with the mobile app.

  1. Client calls supabase.functions.invoke('azure-*').
  2. Supabase Edge Function (server-side) receives the request.
  3. Edge Function injects the AZURE_OPENAI_KEY or AZURE_SPEECH_KEY (stored as secret in Supabase).
  4. Edge Function communicates with Azure.
  5. Edge Function returns the final result to the client.

This ensures that even if the app bundle is decompiled, no third-party keys are exposed.