mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-02-07 01:11:22 +08:00
ggwave-to-file : update python example
This commit is contained in:
committed by
Georgi Gerganov
parent
8834e201a9
commit
79697bd196
@@ -1,7 +1,9 @@
|
||||
import sys
|
||||
import requests
|
||||
import wave
|
||||
|
||||
def ggwave(message: str, protocolId: int = 1, sampleRate: float = 48000, volume: int = 50, payloadLength: int = -1):
|
||||
|
||||
def ggwave(message: str, file: str, protocolId: int = 1, sampleRate: float = 48000, volume: int = 50, payloadLength: int = -1) -> None:
|
||||
|
||||
url = 'https://ggwave-to-file.ggerganov.com/'
|
||||
|
||||
@@ -15,11 +17,15 @@ def ggwave(message: str, protocolId: int = 1, sampleRate: float = 48000, volume:
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
if response == '':
|
||||
if response == '' or b'Usage: ggwave-to-file' in response.content:
|
||||
raise SyntaxError('Request failed')
|
||||
|
||||
return response
|
||||
with wave.open(file, 'wb') as f:
|
||||
f.setnchannels(1)
|
||||
f.setframerate(sampleRate)
|
||||
f.setsampwidth(2)
|
||||
f.writeframes(response.content)
|
||||
|
||||
result = ggwave("Hello world!")
|
||||
|
||||
sys.stdout.buffer.write(result.content)
|
||||
if __name__ == "__main__":
|
||||
ggwave("Hello world!", "hello_world.wav")
|
||||
|
||||
Reference in New Issue
Block a user