Sub topic 13
Privacy, consent, and disclosing synthetic voices
Speech data is more sensitive than most text input. A recording carries what a person said, how they sound, who else was in the room, and sometimes where they were. This chapter assumes you can already call the transcription and speech endpoints and have built the turn-based voice loop from earlier chapters. It covers what to collect, how to get consent, how to limit retention, and how to tell users they are hearing a synthetic voice.
This is engineering guidance, not legal advice. Recording and biometric rules differ by country and by US state, so confirm your obligations with counsel before launch.
Why voice data needs extra care
A voice recording is personal data in most privacy regimes. Three properties make it harder to handle than typed text:
- It identifies people. A voice can work as a biometric identifier. Some jurisdictions regulate voiceprints separately from ordinary personal data.
- It captures bystanders. A meeting recording includes people who never opened your app and never agreed to anything.
- It leaks content you did not ask for. Users read out card numbers, addresses, and health details without being prompted. Background audio can reveal even more.
In a hosted API pipeline, the audio leaves your system. Each stage (transcription, chat model, speech synthesis) is a separate data transfer to a provider, and each one needs to be covered by your privacy notice.
Map where the data goes
Before you write a consent screen, trace every place audio and text are stored or sent. The diagram below shows a typical turn.
The dotted lines are the ones teams forget. Your own logs, temporary files, and chunk files from the long-audio chapter are copies. So is anything the provider retains under its data policy.
Consent
What to ask for
Obtain consent before the microphone opens, not after. A usable consent step states:
- That audio is recorded and sent to third-party services for transcription.
- Whether the audio or transcript is stored, and for how long.
- Whether the data is used for anything else, such as improving your product.
- How the user can withdraw consent and delete their data.
Keep consent separate from the general terms of service. Record when and what version of the text the user accepted.
Recording other people
If your app records a room, a call, or a meeting, the user's consent does not cover other participants. Some jurisdictions require every party to a conversation to consent to recording. Practical options are an audible or visible recording notice, a prompt asking the host to confirm that participants were told, and a setting that disables recording by default.
Minimize what you send and keep
Data you never collect cannot leak. Apply these habits in the pipeline.
- Send only what is needed. Trim silence and unrelated segments before upload. Use the chunking code from the long-audio chapter only on audio the user actually submitted.
- Delete temporary files. Chunk files and uploads should be removed as soon as the transcript returns.
- Decide whether to keep audio at all. Most apps need the transcript, not the recording. Keeping only text shrinks your exposure.
- Set a retention period. Choose a number of days, enforce it with a scheduled job, and document it in the privacy notice.
- Check the provider's data terms. Look up how long the provider keeps API inputs, whether inputs are used for training, and whether a zero-retention option exists for your account type. These terms change, so read the current documentation instead of relying on memory.
The following helper transcribes a file and always removes the temporary copy, even when the call fails.
import os
from openai import OpenAI
client = OpenAI()
def transcribe_and_discard(path):
try:
with open(path, "rb") as audio_file:
return client.audio.transcriptions.create(
model="whisper-1",
file=audio_file,
).text
finally:
if os.path.exists(path):
os.remove(path)Deleting a file with os.remove does not securely erase it from every storage layer, and it does not touch backups or provider-side copies. Treat it as one control among several.
Redact sensitive content from transcripts
Transcripts often contain identifiers that your downstream systems do not need. Redacting them before logging or before sending text to the chat model reduces harm if a log is exposed.
The example below masks card-like digit runs and email addresses with regular expressions. Patterns like these are a first filter, not a complete solution. They miss spoken forms such as "four one one one", which the transcriber may write out as words, so test against your real transcripts.
import re
CARD_PATTERN = re.compile(r"\b(?:\d[ -]?){13,16}\b")
EMAIL_PATTERN = re.compile(r"\b[\w.+-]+@[\w-]+\.[\w.-]+\b")
def redact(text):
text = CARD_PATTERN.sub("[CARD]", text)
text = EMAIL_PATTERN.sub("[EMAIL]", text)
return text
print(redact("Charge 4111 1111 1111 1111 and email [email protected]"))This prints Charge [CARD] and email [EMAIL]. For production, consider a dedicated PII detection service and keep the redaction step outside the code path that handles model output.
Logging
Log metadata (timestamps, durations, error codes, request IDs) rather than content. If you must log transcripts for debugging, redact first, restrict access, and apply the same retention limit as the rest of your data.
Voice cloning and impersonation
Hosted text-to-speech services offer a fixed set of preset voices, and some providers offer custom or cloned voices under stricter terms. Cloning a real person's voice without their permission can enable fraud and harassment, and it can violate both provider policy and law.
If you ever build on a voice-cloning feature, apply these rules:
- Clone only a voice whose owner has given explicit, documented permission for that use.
- Never present a cloned voice as the real person in a context where listeners could be misled.
- Keep a record of the permission and let the voice owner revoke it.
- Do not use synthetic voices to impersonate public figures, officials, or a user's family or colleagues.
Using a preset voice such as the one in the speech chapter avoids the cloning question, though it still triggers the disclosure duty described next.
Disclosing synthetic voices
People should know when they are talking to a machine. Several providers' usage policies require you to tell end users that the voice they hear is AI-generated, and some jurisdictions have rules about automated calls and AI interaction. Disclosure also builds trust: users who discover afterwards that a "person" was synthetic tend to feel deceived.
How to disclose
| Context | Practical disclosure |
|---|---|
| Voice assistant in an app | A persistent label such as "AI voice" near the player, plus a note in onboarding |
| Phone or call-center agent | A spoken statement at the start: "This is an automated assistant." |
| Generated audio file shared outside the app | A note in the file metadata and in the surrounding text or page |
| Narration of articles | A visible line stating the audio is computer-generated |
Make the disclosure early and in the same channel as the voice. A line buried in terms of service does not count for a caller who only hears audio.
The voice loop can enforce a spoken disclosure on the first turn. This version wraps the earlier voice_turn idea and prepends a greeting only once per session.
from openai import OpenAI
client = OpenAI()
DISCLOSURE = "Hi, I'm an automated assistant using a synthetic voice. "
def speak(text, output_path, first_turn):
spoken = DISCLOSURE + text if first_turn else text
with client.audio.speech.with_streaming_response.create(
model="tts-1",
voice="alloy",
input=spoken,
response_format="mp3",
) as response:
response.stream_to_file(output_path)
return spoken
speak("How can I help you today?", "reply.mp3", first_turn=True)Adding the disclosure in code, outside the model's control, matters. A prompt that asks the model to disclose can be overridden by a user, and the model may skip it. A fixed string you prepend cannot be skipped.
Common mistakes
- Sending audio to a provider before the user has consented.
- Keeping raw audio indefinitely because storage is cheap.
- Logging full transcripts in plain text to a shared logging service.
- Assuming one user's consent covers every speaker in a recording.
- Relying on the system prompt alone for disclosure.
- Forgetting that chunk files, caches, and backups are copies that need deletion too.
- Using a voice that closely imitates a real person without permission.
Checklist before launch
- Consent text shown before recording, stored with a timestamp and version.
- A data-flow diagram listing every provider and store.
- Retention periods set and enforced by a job.
- Redaction applied before logging and before storing text.
- A deletion path for a user's audio and transcripts.
- A disclosure shown or spoken at the start of every synthetic voice interaction.
- Voice permission records for any custom voice.
Exercise
Your app lets users record a team meeting and returns a summary read aloud by a synthetic voice. Name two privacy risks that the host's consent alone does not cover, and one disclosure you must add.
Show answer
First, other participants in the meeting have not consented to being recorded or to having their speech sent to third-party providers, and some jurisdictions require every party's consent. Second, the transcript and the temporary or chunked audio files can persist in logs, storage, or provider retention beyond what the user expects, so you need a retention limit, deletion, and redaction. The disclosure to add is that the summary is read by an AI-generated voice, shown as a label near the player or stated at the start of the audio, ideally prepended in code instead of relying on the model.
Exercise
Why is it safer to prepend the disclosure string in code than to tell the model in the system prompt to introduce itself as an AI?
Show answer
A system prompt instruction is a request to the model, and a user message, a transcript containing injected instructions, or an ordinary model error can lead it to skip or contradict the instruction. A string the application adds before sending text to the speech endpoint is deterministic, so the disclosure is spoken on every first turn regardless of what the model generates.