├── .gitignore ├── requirements.txt ├── voicos.env ├── Dockerfile ├── DateFilter.py ├── docker-compose.yml ├── .github └── workflows │ └── publish-container.yml ├── README.MD ├── bot.py └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | data/ 3 | venv/ 4 | postgres.conf 5 | voicos.dev.env 6 | voicos*.json 7 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | google-cloud-speech==2.12.0 2 | google-cloud-storage==2.1.0 3 | pymediainfo==5.1.0 4 | python-telegram-bot==13.11 5 | psycopg2-binary==2.9.3 -------------------------------------------------------------------------------- /voicos.env: -------------------------------------------------------------------------------- 1 | VOICOS_ADMIN_ID=YOUR_ADMIN_ID 2 | VOICOS_BUCKET=YOUR_GOOGLE_BUCKET 3 | VOICOS_TOKEN=YOUR_BOT_TOKEN 4 | GOOGLE_APPLICATION_CREDENTIALS=/app/credentials.json -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.9-slim-buster 2 | 3 | COPY bot.py /app/bot.py 4 | COPY DateFilter.py /app/DateFilter.py 5 | COPY requirements.txt / 6 | 7 | RUN apt-get update && apt-get install libmediainfo0v5 ffmpeg -y 8 | RUN pip3 install -r requirements.txt 9 | 10 | WORKDIR app 11 | 12 | ENTRYPOINT ["python3", "bot.py"] -------------------------------------------------------------------------------- /DateFilter.py: -------------------------------------------------------------------------------- 1 | from typing import Union, Dict, Optional 2 | 3 | from telegram import Message 4 | from telegram.ext import MessageFilter 5 | from datetime import datetime, timezone 6 | 7 | 8 | class DateFilter(MessageFilter): 9 | def filter(self, message: Message) -> Optional[Union[bool, Dict]]: 10 | return (datetime.now(timezone.utc) - message.date).days <= 3 11 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | 5 | db: 6 | image: postgres:14.2 7 | restart: unless-stopped 8 | environment: 9 | - POSTGRES_USER=bot 10 | - POSTGRES_PASSWORD=voicosdb 11 | - POSTGRES_DB=voicos 12 | - POSTGRES_HOST_AUTH_METHOD=trust 13 | volumes: 14 | - ./data:/var/lib/postgresql/data:rw 15 | - ./postgres.conf:/etc/postgresql/postgresql.conf:ro 16 | 17 | app: 18 | build: 19 | context: ./ 20 | depends_on: 21 | - db 22 | image: ghcr.io/graynk/voicos 23 | restart: unless-stopped 24 | env_file: 25 | - voicos.env 26 | volumes: 27 | - ./credentials.json:/app/credentials.json:ro 28 | -------------------------------------------------------------------------------- /.github/workflows/publish-container.yml: -------------------------------------------------------------------------------- 1 | name: Publish Docker image 2 | on: 3 | release: 4 | types: [published] 5 | jobs: 6 | push_to_registry: 7 | name: Push Docker image to GitHub Packages 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout code 11 | uses: actions/checkout@v2 12 | - 13 | name: Set up QEMU 14 | uses: docker/setup-qemu-action@v1 15 | - 16 | name: Set up Docker Buildx 17 | uses: docker/setup-buildx-action@v1 18 | - 19 | name: Login to Github Actions 20 | uses: docker/login-action@v1 21 | with: 22 | username: ${{ github.actor }} 23 | password: ${{ secrets.CR_PAT }} 24 | registry: ghcr.io 25 | - 26 | name: Build and push 27 | uses: docker/build-push-action@v2 28 | with: 29 | context: . 30 | pull: true 31 | push: true 32 | tags: ghcr.io/graynk/voicos:latest 33 | platforms: linux/amd64,linux/arm64 34 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # Voicos 2 | Simple Telegram bot that converts voice messages to text using Google Speech. Can be found at [@voicos_bot](https://t.me/voicos_bot), but currently disabled, since Google won't accept my credit cards :') 3 | 4 | ## Dependencies 5 | * python-telegram-bot 6 | * pymediainfo (and a system library libmediainfo) 7 | * google-cloud-speech 8 | * google-cloud-storage 9 | * psycopg2-binary (and, well, PostgreSQL itself) 10 | 11 | ## Installation 12 | 1. Install the libraries via pip: 13 | ``` 14 | pip install -r requirements.txt 15 | ``` 16 | 2. Go to [Google Cloud](https://cloud.google.com/) and set up a new project. You will need Google Speech API. 17 | For messages longer than 1 minute you will also need Google Storage 18 | 3. Generate new service account and download a private key as JSON 19 | 4. Set environment variable `GOOGLE_APPLICATION_CREDENTIALS` to the file path of the JSON key 20 | (see [here](https://cloud.google.com/speech-to-text/docs/quickstart-client-libraries) for more instructions) 21 | 5. Go to the Google Storage page and create a new bucket 22 | 6. Message [@BotFather](https://t.me/BotFather) on Telegram to [create a new bot](https://core.telegram.org/bots#6-botfather) 23 | 7. Set up `VOICOS_TOKEN`, `VOICOS_BUCKET` and `VOICOS_ADMIN_ID` environment variables 24 | 8. Set up PostgreSQL and change connection string in bot.py 25 | 9. Run the bot 26 | `python3 bot.py` 27 | 28 | 29 | ## Docker support 30 | You will need to pass your credentials JSON to the container and to pass the environment variables with tokens and such. 31 | 32 | With PostgreSQL already set up natively (please don't leave it with open ports, I will not responsible), your run command will look something like this: 33 | 34 | ```Bash 35 | docker run -d --restart unless-stopped --name voicos \ 36 | --mount type=bind,source=/path/to/credentials.json,target=/app/credentials.json,readonly \ 37 | --env-file voicos.env \ 38 | ghcr.io/graynk/voicos:latest 39 | ``` 40 | 41 | To use Postgre in container as well, put `docker-compose.yml`, `credentials.json`, `voicos.env`, `data` directory and your `postgres.conf` 42 | in the same directory, then run: 43 | ```Bash 44 | sudo docker-compose up & 45 | ``` 46 | 47 | Hopefully you know what you're doing and can edit `docker-compose.yml` if needed, because I don't have any desire to write a longer instruction than this. 48 | 49 | ## Usage 50 | Launch the bot, forward the voice message, easy. Works in group chats as well. 51 | For messages longer than 1 minute the bot uses long recognition with uploading to Google Storage 52 | -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import io 4 | import os 5 | import subprocess 6 | from typing import List 7 | 8 | import psycopg2 9 | from google.cloud import storage 10 | from google.cloud.speech import SpeechClient, RecognitionConfig, RecognitionAudio, RecognizeResponse 11 | from pymediainfo import MediaInfo 12 | from telegram import ChatAction, Update, Message 13 | from telegram.constants import MAX_MESSAGE_LENGTH 14 | from telegram.error import TimedOut 15 | from telegram.ext import CommandHandler 16 | from telegram.ext import Filters 17 | from telegram.ext import MessageHandler 18 | from telegram.ext import Updater, CallbackContext 19 | 20 | from DateFilter import DateFilter 21 | 22 | SUPPORTED_SAMPLE_RATES = [8000, 12000, 16000, 24000, 48000] 23 | RESAMPLE_RATE = 48000 24 | UPLOAD_LIMIT = 58 # everything longer than a minute we have to upload to bucket. More than 58 seconds to be sure 25 | MY_NERVES_LIMIT = 5 * 60 # five minutes is all you get bruh. don't be tellin stories 26 | POLITE_RESPONSE = 'Sorry, but no messages longer than 5 minutes.' 27 | 28 | TOKEN = os.getenv('VOICOS_TOKEN') 29 | BUCKET_NAME = os.getenv('VOICOS_BUCKET') 30 | ADMIN_CHAT_ID = int(os.getenv('VOICOS_ADMIN_ID')) 31 | PORT = int(os.environ.get('PORT', '5002')) 32 | if not TOKEN or not BUCKET_NAME or not os.getenv('GOOGLE_APPLICATION_CREDENTIALS'): 33 | exit('Check your environment variables') 34 | updater = Updater(TOKEN) 35 | dispatcher = updater.dispatcher 36 | speech_client = SpeechClient() 37 | storage_client = storage.Client() 38 | conn = psycopg2.connect('host=db dbname=voicos user=bot password=voicosdb') 39 | 40 | 41 | def start(update: Update, context: CallbackContext) -> None: 42 | update.effective_message.reply_text("Say stuff, I'll transcribe.\n\nYou can also reply to the voice message with " 43 | "the language code like en-US/ru-RU/something else to use that language when " 44 | "transcribing") 45 | 46 | 47 | def voice_to_text(update: Update, context: CallbackContext) -> None: 48 | message = update.effective_message 49 | if message.voice.duration > MY_NERVES_LIMIT: 50 | message.reply_text(POLITE_RESPONSE, quote=True) 51 | return 52 | 53 | chat_id = update.effective_message.chat.id 54 | file_name = '%s_%s%s.ogg' % (chat_id, update.message.from_user.id, update.message.message_id) 55 | download_and_prep(file_name, message) 56 | 57 | transcriptions = transcribe(file_name, update.message) 58 | 59 | if len(transcriptions) == 0 or transcriptions[0] == '': 60 | message.reply_text('Transcription results are empty. You can try setting language manually by ' 61 | 'replying to the voice message with the language code like ru-RU or en-US', 62 | quote=True) 63 | return 64 | 65 | for transcription in transcriptions: 66 | message.reply_text(transcription, quote=True) 67 | 68 | 69 | def transcribe_with_langcode(update: Update, context: CallbackContext) -> None: 70 | message = update.effective_message 71 | if len(message.text) != 5: 72 | return 73 | 74 | reply_message = message.reply_to_message 75 | if not reply_message.voice: 76 | return 77 | 78 | voice = reply_message.voice 79 | if voice.duration > MY_NERVES_LIMIT: 80 | message.reply_text(POLITE_RESPONSE, quote=True) 81 | return 82 | 83 | file_name = '%s_%s%s.ogg' % (message.chat_id, reply_message.from_user.id, reply_message.message_id) 84 | download_and_prep(file_name, reply_message) 85 | 86 | transcriptions = transcribe(file_name, reply_message, lang_code=message.text, alternatives=[]) 87 | 88 | if len(transcriptions) == 0 or transcriptions[0] == '': 89 | message.reply_text('Welp. Transcription results are still empty, but we tried, right?', 90 | quote=True) 91 | return 92 | for transcription in transcriptions: 93 | message.reply_text(transcription, quote=True) 94 | 95 | 96 | def ping_me(update: Update, context: CallbackContext) -> None: 97 | if context.error is not TimedOut: 98 | err = str(context.error) 99 | print(err) 100 | if len(err) > 4000: 101 | return 102 | context.bot.send_message(chat_id=ADMIN_CHAT_ID, text=err) 103 | 104 | 105 | def transcribe(file_name: str, message: Message, lang_code: str = 'ru-RU', alternatives: List[str] = ['en-US', 'uk-UA']) -> List[str]: 106 | media_info = MediaInfo.parse(file_name) 107 | if len(media_info.audio_tracks) != 1 or not hasattr(media_info.audio_tracks[0], 'sampling_rate'): 108 | os.remove(file_name) 109 | raise ValueError('Failed to detect sample rate') 110 | actual_duration = round(media_info.audio_tracks[0].duration / 1000) 111 | 112 | sample_rate = media_info.audio_tracks[0].sampling_rate 113 | encoding = RecognitionConfig.AudioEncoding.OGG_OPUS 114 | if sample_rate not in SUPPORTED_SAMPLE_RATES: 115 | message.reply_text('Your voice message has a sample rate of {} Hz which is not in the list ' 116 | 'of supported sample rates ({}).\n\nI will try to resample it, ' 117 | 'but this may reduce recognition accuracy' 118 | .format(sample_rate, 119 | ', '.join(str(int(rate / 1000)) + ' kHz' for rate in SUPPORTED_SAMPLE_RATES) 120 | ), 121 | quote=True) 122 | message.reply_chat_action(action=ChatAction.TYPING) 123 | encoding, file_name, sample_rate = resample(file_name) 124 | config = RecognitionConfig( 125 | encoding=encoding, 126 | sample_rate_hertz=sample_rate, 127 | enable_automatic_punctuation=True, 128 | language_code=lang_code, 129 | alternative_language_codes=alternatives, 130 | ) 131 | 132 | try: 133 | response = upload_to_gs(file_name, config) \ 134 | if actual_duration > UPLOAD_LIMIT \ 135 | else regular_upload(file_name, config) 136 | except Exception as e: 137 | print(e) 138 | os.remove(file_name) 139 | return ['Failed'] 140 | 141 | with conn.cursor() as cur: 142 | cur.execute("insert into customer(user_id) values (%s) on conflict (user_id) do nothing;", 143 | (message.chat_id,)) 144 | cur.execute("update customer set balance = balance - (%s) where user_id = (%s);", 145 | (actual_duration, message.chat_id)) 146 | cur.execute("insert into stat(user_id, message_timestamp, duration) values (%s, current_timestamp, %s);", 147 | (message.chat_id, actual_duration)) 148 | conn.commit() 149 | 150 | os.remove(file_name) 151 | 152 | message_text = '' 153 | for result in response.results: 154 | message_text += result.alternatives[0].transcript + '\n' 155 | 156 | return split_long_message(message_text) 157 | 158 | 159 | def regular_upload(file_name: str, config: RecognitionConfig) -> RecognizeResponse: 160 | with io.open(file_name, 'rb') as audio_file: 161 | content = audio_file.read() 162 | audio = RecognitionAudio(content=content) 163 | return speech_client.recognize(config=config, audio=audio) 164 | 165 | 166 | def upload_to_gs(file_name: str, config: RecognitionConfig) -> RecognizeResponse: 167 | bucket = storage_client.get_bucket(bucket_or_name=BUCKET_NAME) 168 | 169 | blob = bucket.blob(file_name) 170 | blob.upload_from_filename(file_name) 171 | audio = RecognitionAudio(uri='gs://%s/%s' % (BUCKET_NAME, file_name)) 172 | response = speech_client.long_running_recognize(config=config, audio=audio).result(timeout=500) 173 | blob.delete() 174 | 175 | return response 176 | 177 | 178 | def split_long_message(text: str) -> List[str]: 179 | length = len(text) 180 | if length < MAX_MESSAGE_LENGTH: 181 | return [text] 182 | 183 | results = [] 184 | for i in range(0, length, MAX_MESSAGE_LENGTH): 185 | results.append(text[i:MAX_MESSAGE_LENGTH]) 186 | 187 | return results 188 | 189 | 190 | def download_and_prep(file_name: str, message: Message) -> None: 191 | message.voice.get_file().download(file_name) 192 | message.reply_chat_action(action=ChatAction.TYPING) 193 | 194 | 195 | def resample(file_name) -> (RecognitionConfig.AudioEncoding, str, int): 196 | new_file_name = file_name + '.raw' 197 | 198 | cmd = [ 199 | 'ffmpeg', 200 | '-loglevel', 'quiet', 201 | '-i', file_name, 202 | '-f', 's16le', 203 | '-acodec', 'pcm_s16le', 204 | '-ar', str(RESAMPLE_RATE), 205 | new_file_name 206 | ] 207 | 208 | try: 209 | subprocess.run(args=cmd) 210 | except Exception as e: 211 | os.remove(file_name) 212 | raise e 213 | 214 | return RecognitionConfig.AudioEncoding.LINEAR16, new_file_name, RESAMPLE_RATE 215 | 216 | 217 | if __name__ == '__main__': 218 | with conn.cursor() as cur: 219 | cur.execute("create table if not exists customer (user_id bigint primary key, balance integer default 1200);") 220 | cur.execute("create table if not exists stat (id serial primary key, user_id bigint references customer(user_id), message_timestamp timestamp, duration integer);") 221 | conn.commit() 222 | 223 | start_handler = CommandHandler('start', start) 224 | voice_handler = MessageHandler(Filters.voice & DateFilter(), voice_to_text, run_async=True) 225 | language_handler = MessageHandler(Filters.reply & Filters.text & DateFilter(), transcribe_with_langcode, 226 | run_async=True) 227 | 228 | dispatcher.add_handler(start_handler) 229 | dispatcher.add_handler(voice_handler) 230 | dispatcher.add_handler(language_handler) 231 | dispatcher.add_error_handler(ping_me) 232 | 233 | updater.start_polling() 234 | updater.idle() 235 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------