# gTTS : Google Text to Speech API : Google에서 제공하는 TTS 서비스. gTTS라는 모듈을 인스톨해야 함
"""
'en'으로 지정했을 때 한글이 text에 포함되어 있으면 이를 무시하지만, 'ko'일때 text내의 영문은 무시되지 않고 음성합성을 수행한다(아주 이상함)
영어는 여자 성우, 한글은 남자 성우이다(변경 불가능)
"""
from gtts import gTTS
import pygame
import time
text ="안녕하세요, 여러분. 파이썬으로 노는 것은 재미있습니다!!!"
tts = gTTS(text=text, lang='ko')
tts.save("helloKO.mp3")
# Initialize Pygame mixer
pygame.mixer.init()
# Load the audio file
pygame.mixer.music.load("helloKO.mp3")
# Play the audio file
pygame.mixer.music.play()
# Allow time for the audio to play
time.sleep(10)
# Stop the playback
pygame.mixer.music.stop()
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
pyttsx3is 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 asNo module named win32com.client,No module named win32, orNo module named win32api, you will need to additionally installpypiwin32.
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()
The image of a document page is represented by aPixmap, and the simplest way to create a pixmap is via methodPage.get_pixmap().
This method has many options to influence the result. The most important among them is theMatrix, which lets youzoom, rotate, distort or mirror the outcome.
In the following, we apply azoom 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 specifypix=page.get_pixmap(dpi=300). Apart from notation brevity, this approach has the additional advantage that thedpi value is saved with the imagefile – which does not happen automatically when using the Matrix notation.