반응형
반응형

pyttsx3

*** https://medium.com/analytics-vidhya/easy-way-to-build-an-audiobook-using-python-20fc7d6fb1af

 

Easy Way To Build An Audiobook Using Python

An audiobook is nothing but a book that was recorded in an audio format. It can also be stated as a book that is being read aloud…

medium.com

 

pip install gTTS  https://pypi.org/project/gTTS/

 

https://pypi.org/project/pyttsx3/

 

pyttsx3

Text to Speech (TTS) library for Python 2 and 3. Works without internet connection or delay. Supports multiple TTS engines, including Sapi5, nsss, and espeak.

pypi.org

Text to Speech (TTS) library for Python 2 and 3. Works without internet connection or delay. Supports multiple TTS engines, including Sapi5, nsss, and espeak.

 

pip install pyttsx3

Project description

pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline, and is compatible with both Python 2 and 3.

Installation

pip install pyttsx3

If you recieve errors such as No module named win32com.client, No module named win32, or No module named win32api, you will need to additionally install pypiwin32.

Usage :

import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()

Changing Voice , Rate and Volume :

import pyttsx3
engine = pyttsx3.init() # object creation

""" RATE"""
rate = engine.getProperty('rate')   # getting details of current speaking rate
print (rate)                        #printing current voice rate
engine.setProperty('rate', 125)     # setting up new voice rate


"""VOLUME"""
volume = engine.getProperty('volume')   #getting to know current volume level (min=0 and max=1)
print (volume)                          #printing current volume level
engine.setProperty('volume',1.0)    # setting up volume level  between 0 and 1

"""VOICE"""
voices = engine.getProperty('voices')       #getting details of current voice
#engine.setProperty('voice', voices[0].id)  #changing index, changes voices. o for male
engine.setProperty('voice', voices[1].id)   #changing index, changes voices. 1 for female

engine.say("Hello World!")
engine.say('My current speaking rate is ' + str(rate))
engine.runAndWait()
engine.stop()

"""Saving Voice to a file"""
# On linux make sure that 'espeak' and 'ffmpeg' are installed
engine.save_to_file('Hello World', 'test.mp3')
engine.runAndWait()

Full documentation of the Library

https://pyttsx3.readthedocs.io/en/latest/

Included TTS engines:

  • sapi5
  • nsss
  • espeak

Feel free to wrap another text-to-speech engine for use with pyttsx3.

반응형
반응형

‘굶주린 짐승’처럼 물·전기 퍼먹는 이것, 전세계 골머리

https://www.chosun.com/economy/tech_it/2024/03/07/Z7WTVPHCAVAMPA5NHMROJG2QPU/

 

‘굶주린 짐승’처럼 물·전기 퍼먹는 이것, 전세계 골머리

굶주린 짐승처럼 물·전기 퍼먹는 이것, 전세계 골머리 비즈 톡

www.chosun.com

인공지능(AI) 시대 필수 인프라로 꼽히는 데이터센터가 ‘굶주린 짐승’처럼 전기와 물을 먹어치우면서 각국 정부와 기업들이 골머리를 앓고 있습니다. 데이터센터에서 물과 전기 사용량을 줄이기 위해 당국이 규제 강도를 높이자 기업들은 기술 개발에 나서는 등 대책 마련에 분주합니다.

네이버 데이터센터 내 '서버룸'. 수많은 서버를 보관하는 공간 (네이버 제공) /뉴스1

최근 생성형 AI 열풍이 불면서 AI 학습과 서비스에 필요한 데이터센터가 세계 곳곳에서 건설되고 있습니다. 현재 8000개에 달하는 데이터센터가 운영 중입니다. 문제는 데이터센터에서 발생하는 열을 식히기 위해 엄청난 양의 물이 필요하다는 겁니다. 2022년 데이터센터 유지를 위해 마이크로소프트(MS)는 물 사용량을 전년보다 34%, 구글은 22% 늘렸습니다. 2027년에는 세계 데이터센터 물 소비량이 영국의 한 해 물 소비량의 절반에 해당할 것이란 전망도 나왔습니다. 특히 AI 데이터센터는 일반 데이터센터보다 배 이상 전력을 소모하기 때문에 국가 전력망에도 큰 부담을 줍니다.

칠레 환경 법원은 구글의 데이터센터 건설 허가를 일부 취소하며, 구글에 서버 냉각 시스템 변경을 요청했습니다. 아일랜드 더블린 시 당국은 지난해 신규 데이터센터 건설 프로젝트를 거부했고, 미국 버지니아주와 독일은 최근 주거 지역 인근에 데이터센터 허가를 제한하고 재생 에너지 사용과 폐열 재사용을 요구하고 있습니다. 극심한 가뭄을 겪고 있는 우루과이에서는 구글의 신규 데이터센터 건설을 두고 주민들이 거세게 반발하고 있습니다. 기업들은 전력 효율을 높일 시스템을 도입하고 물을 재사용하는 방식으로 대처하고 있습니다. 24시간 운영 가능한 소형 모듈 원자로(SMR)까지 대안으로 거론되고 있습니다.

산업통상자원부에 따르면 국내 데이터센터 전력 수요는 2022년 1762MW(메가와트)에서 2029년 4만9397MW로 폭증할 전망입니다. 한국도 몇 년 내에 데이터센터발 물 부족과 전력망 문제를 겪게 될 수도 있다는 뜻입니다. 각국의 사례를 반면교사 삼아 미리 대비해야 데이터센터가 한국의 AI 경쟁력을 발목 잡는 일을 막을 수 있을 것 같습니다.

반응형
반응형

https://pandas.pydata.org/pandas-docs/stable/index.html

 

pandas documentation — pandas 2.2.1 documentation

API reference The reference guide contains a detailed description of the pandas API. The reference describes how the methods work and which parameters can be used. It assumes that you have an understanding of the key concepts.

pandas.pydata.org

 

Community tutorials — pandas 2.2.1 documentation

 

pandas.pydata.org

 

반응형
반응형

[python] PyMuPDF 에서 해상도 올리기. PDF to IMG

How to Increase Image Resolution

 

https://pymupdf.readthedocs.io/en/latest/recipes-images.html

 

Images - PyMuPDF 1.23.25 documentation

Previous Text

pymupdf.readthedocs.io

The image of a document page is represented by a Pixmap, and the simplest way to create a pixmap is via method Page.get_pixmap().

This method has many options to influence the result. The most important among them is the Matrix, which lets you zoom, rotate, distort or mirror the outcome.

Page.get_pixmap() by default will use the Identity matrix, which does nothing.

In the following, we apply a zoom factor of 2 to each dimension, which will generate an image with a four times better resolution for us (and also about 4 times the size):

zoom_x = 2.0  # horizontal zoom
zoom_y = 2.0  # vertical zoom
mat = fitz.Matrix(zoom_x, zoom_y)  # zoom factor 2 in each dimension
pix = page.get_pixmap(matrix=mat)  # use 'mat' instead of the identity matrix

dpi = 600
pix = page.get_pixmap(dpi)

Since version 1.19.2 there is a more direct way to set the resolution: Parameter "dpi" (dots per inch) can be used in place of "matrix". To create a 300 dpi image of a page specify pix = page.get_pixmap(dpi=300). Apart from notation brevity, this approach has the additional advantage that the dpi value is saved with the image file – which does not happen automatically when using the Matrix notation.

 
반응형
반응형

vscode-pdf

 

Display pdf file in VSCode.

 
반응형
반응형

모바일 웹에서 뒤로가기 버튼 선택시 history.pushstate 사용해서 뒤로가기 이벤트 확인하기

 

모바일 웹에서 뒤로가기 버튼을 처리하려면 JavaScript를 사용하여 history.pushState를 활용할 수 있습니다. popstate 이벤트를 사용하여 뒤로가기 버튼의 클릭을 감지할 수 있습니다. 아래는 간단한 예제 코드입니다.

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>뒤로가기 이벤트 확인</title>
</head>
<body>
    <h1>뒤로가기 이벤트 확인</h1>

    <script>
        // 현재 상태 저장
        history.pushState({ page: 1 }, "Title 1", "?page=1");

        // 뒤로가기 이벤트 처리
        window.addEventListener('popstate', function(event) {
            // event.state에는 현재 상태의 데이터가 들어있습니다.
            if (event.state) {
                alert('뒤로가기 버튼이 눌렸습니다. 페이지 상태: ' + JSON.stringify(event.state));
            } else {
                // 더 이상 뒤로 갈 수 없을 때, 예를 들어 초기 페이지에서 뒤로가기 버튼을 눌렀을 때 처리할 내용을 여기에 추가할 수 있습니다.
                alert('뒤로 갈 수 없습니다.');
            }
        });

        // 새로운 상태 추가 및 주소 변경
        function changeState() {
            const newState = { page: 2 };
            history.pushState(newState, "Title 2", "?page=2");
        }
    </script>

    <!-- 버튼을 클릭하여 상태를 변경하고 뒤로가기 이벤트를 확인할 수 있습니다. -->
    <button onclick="changeState()">새로운 상태로 이동</button>
</body>
</html>
반응형

+ Recent posts