https://github.com/louis70109/line-bot-google-tts
https://github.com/louis70109/line-bot-google-tts
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/louis70109/line-bot-google-tts
- Owner: louis70109
- Created: 2022-02-11T04:10:54.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-04-20T15:45:22.000Z (about 3 years ago)
- Last Synced: 2025-01-31T22:11:23.874Z (4 months ago)
- Language: Python
- Size: 942 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: change_bot_url.sh
Awesome Lists containing this project
README
# Speech
- Create Cloud Storage

- [IAM & Admin](https://console.cloud.google.com/iam-admin)
- Create a **Service Account**
- Go to Service Account `KEYS` tab
- ADD KEY -> Create a new key -> Select `JSON` -> Download it
# Speech to Text
- Use IAM key to access STT API.
- [code reference](https://cloud.google.com/speech-to-text/docs/samples/speech-transcribe-async-gcs#speech_transcribe_async_gcs-python)
- set timeout to 15 seconds.
- `zh-TW` Language support from [doc](https://cloud.google.com/speech-to-text/docs/languages).
- `MP3` audio currently is BETA feature. It's not support in SDK now(2022/02).
- LINE message audio `m4a` could force change `mp3`, and it was `16000` Hz.
- In [doc](https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig#AudioEncoding), `sampleRateHertz` supported `MP3`.
- So we could use `WEBM_OPUS` as **AudioEncoding** parameter.
- Following code could recognize the audio which is from LINE message with `m4a` format.```python
config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.WEBM_OPUS,
sample_rate_hertz=16000,
language_code="zh-TW",
)
```## Dialogflow
- Set on your [Dialogflow Console](https://dialogflow.cloud.google.com/)
- Add Entities.
- Add Entities in Intents dialog.
- Add more and more phrases to train it. See [doc](https://cloud.google.com/dialogflow/es/docs/intents-training-phrases#annotation).
Get intents.
```python
intent = dict(response.query_result.parameters)
```> Code from [Quick Start](https://cloud.google.com/dialogflow/es/docs/quick/api).
## Binding STT and Dialogflow Result

## Save data to Firebase
> [refs](https://firebase.google.com/docs/firestore/query-data/get-data#python)
- Project setting -> Service Account -> Add -> Choose Python -> Create Firebase Token JSON to current project.
- 中文: 專案設定 -> 服務帳戶 -> 建立 -> 選擇 Python -> 產生金鑰 -> 到專案下
- create a Firestore Database and collection.```python
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
cred = credentials.Certificate(os.getenv('FIREBASE_CREDENTIALS'))
firebase_admin.initialize_app(cred)
db = firestore.client()
def create_user(user_dict):
doc_ref = db.collection("users").document(f"user_{user_dict.get('id')}")
doc_ref.set(user_dict)
return {}
```# Quick Start
Install packages.
```bash
pip install -r requrements.txt
```Copy and fill environment variables.(`.env`)
```
cp .env.sample .env
```Run application.
```
python main.py
```Change LINE Bot development webhook url.
```
sh change_bot_url.sh BOT_ACCESS_TOKEN https://YOUR_DOMAIN/webhooks/line
```## By Docker
TODO
## Subtitle type
Audio:
```python
audios_{audio_dict.get('bucket')}_{audio_dict.get('name')}
```Subtitle:
```python
subtitles_{audio.get('id')}_{count}
```# LICENSE
MIT