Architectural Document for Google TTS Python package
This document is using arc42 template and C4 model.
[TOC]
1. Introduction and Goals
Requirements Overview:
Provide text-to-speech functionality for various languages.
Handle texts of varying lengths, including very long texts.
Support real-time audio playback.
More details can be found in User Stories
2. Constraints
Technical Constraints:
Requires internet connectivity for accessing the Google TTS service.
Dependent on external libraries (
requests
,playsound
).
Operational Constraints:
Audio playback capabilities needed on the host machine.
3. Context and Scope
External Interfaces:
Google Translate TTS API for fetching speech audio.
User Interfaces:
Calling the text-to-speech function play_tts(text, language)
Hello World! Example
This example demonstrates how to use the google_text_to_speech
package to convert a simple text string, “Hello World!”, into speech.
Prerequisites
Ensure that you have installed the google_text_to_speech
package:
pip install google_text_to_speech
from google_text_to_speech import play_tts
# Text to be converted to speech
text = "Hello World!"
language = "en" # Language code (e.g., "en" for English)
# Calling the text-to-speech function
play_tts(text, language)
4. Solution Strategy
Split long texts into sentences to avoid exceeding URL length limits.
Use multithreading to handle audio playback and file removal.
Organize the project using a
src
directory for better separation of source code and tests.
5. Building Block View
5.1 Context Diagram:
System: Google Translate TTS Python Module
Users: Developers using the module
External Systems: Google Translate TTS API
5.2 Container Diagram:
Container: Python Module with different functionalities
5.3 Component Diagram (focusing on the play_tts function):
Components: URL Generator, Audio Player, and Error Handler
6. Runtime View
Sequence Diagram for
play_tts
Execution (PlantUML):
7. Deployment View (PlantUML Diagram)
Deployment of the Module:
8. Crosscutting Concepts
Concurrency: Use of threading for simultaneous audio playback and file operations.
Error Handling: Manage errors related to network issues, file operations, and external API limitations.
9. Architecture Decisions
Decision to split text into sentences for handling long texts.
Use of external TTS service (Google TTS) for speech synthesis.
Adoption of a
src
directory structure for the project to cleanly separate source code from tests and documentation.
10. Quality Requirements
Performance: Handle long texts without significant delays.
Usability: Accurate and clear audio playback in requested languages.
10.1 Quality Reports
The code quality report - Navigate to the Pipelines page, select the latest pipeline, and open the
Code Quality
tab.The test results report - Navigate to the Pipelines page, select the latest pipeline, and open the
Tests
tab.
Lint score:
11. Risks and Technical Debt
Dependency on the availability and limitations of Google TTS API.
Potential issues with audio playback on different operating systems.
12. Glossary
TTS: Text-to-Speech
API: Application Programming Interface