-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplay_audio_sound.py
More file actions
43 lines (31 loc) · 874 Bytes
/
play_audio_sound.py
File metadata and controls
43 lines (31 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# import pygame
# pygame.mixer.init()
# def read(file_path):
# outfile = "cache/temp.mp3"
# pygame.mixer.music.load(outfile)
# pygame.mixer.music.play()
# def stop():
# pygame.mixer.music.stop()
# def pause():
# pygame.mixer.music.pause()
# def unpause():
# pygame.mixer.music.unpause()
import pyttsx3
import pygame
pygame.mixer.init()
engine = pyttsx3.init()
def read(text):
outfile = "cache/temp.wav"
voices = engine.getProperty("voices")
engine.setProperty("rate", 150)
engine.setProperty("voice", voices[1].id)
engine.save_to_file(text, outfile)
engine.runAndWait()
pygame.mixer.music.load(outfile)
pygame.mixer.music.play()
def stop():
pygame.mixer.music.stop()
def pause():
pygame.mixer.music.pause()
def unpause():
pygame.mixer.music.unpause()