1+ {
2+ "cells" : [
3+ {
4+ "cell_type" : " markdown" ,
5+ "metadata" : {},
6+ "source" : [
7+ " # Fish Audio SDK - Getting Started\n " ,
8+ " \n " ,
9+ " This notebook demonstrates the basic usage of the Fish Audio Python SDK:\n " ,
10+ " - Initialize the client\n " ,
11+ " - Convert text to speech\n " ,
12+ " - Save and play audio\n " ,
13+ " - Use different voices"
14+ ]
15+ },
16+ {
17+ "cell_type" : " markdown" ,
18+ "metadata" : {},
19+ "source" : [
20+ " ## Setup\n " ,
21+ " \n " ,
22+ " First, install the SDK and set your API key:\n " ,
23+ " \n " ,
24+ " ```bash\n " ,
25+ " pip install fishaudio\n " ,
26+ " export FISH_API_KEY=\" your_api_key\"\n " ,
27+ " ```\n " ,
28+ " \n " ,
29+ " Or create a `.env` file with `FISH_API_KEY=your_api_key`"
30+ ]
31+ },
32+ {
33+ "cell_type" : " code" ,
34+ "execution_count" : null ,
35+ "metadata" : {
36+ "ExecuteTime" : {
37+ "end_time" : " 2025-12-17T02:19:01.713412Z" ,
38+ "start_time" : " 2025-12-17T02:19:01.692232Z"
39+ }
40+ },
41+ "outputs" : [],
42+ "source" : " from dotenv import load_dotenv\n from fishaudio import FishAudio\n from fishaudio.utils import play\n # from fishaudio.utils import save # Uncomment if saving audio to file\n\n load_dotenv()\n\n client = FishAudio()"
43+ },
44+ {
45+ "cell_type" : " markdown" ,
46+ "metadata" : {},
47+ "source" : [
48+ " ## Simple Text-to-Speech\n " ,
49+ " \n " ,
50+ " Convert text to speech and play it directly in the notebook."
51+ ]
52+ },
53+ {
54+ "cell_type" : " code" ,
55+ "execution_count" : null ,
56+ "metadata" : {
57+ "ExecuteTime" : {
58+ "end_time" : " 2025-12-17T02:19:02.811072Z" ,
59+ "start_time" : " 2025-12-17T02:19:01.715025Z"
60+ }
61+ },
62+ "outputs" : [],
63+ "source" : [
64+ " audio = client.tts.convert(text=\" Hello! Welcome to Fish Audio.\" )\n " ,
65+ " \n " ,
66+ " play(audio, notebook=True)"
67+ ]
68+ },
69+ {
70+ "cell_type" : " markdown" ,
71+ "metadata" : {},
72+ "source" : [
73+ " ## Save Audio to File\n " ,
74+ " \n " ,
75+ " Save the generated audio to an MP3 file."
76+ ]
77+ },
78+ {
79+ "cell_type" : " code" ,
80+ "execution_count" : null ,
81+ "metadata" : {
82+ "ExecuteTime" : {
83+ "end_time" : " 2025-12-17T02:19:02.822441Z" ,
84+ "start_time" : " 2025-12-17T02:19:02.818578Z"
85+ }
86+ },
87+ "outputs" : [],
88+ "source" : [
89+ " # audio = client.tts.convert(text=\" This audio will be saved to a file.\" )\n " ,
90+ " # save(audio, \" output.mp3\" )"
91+ ]
92+ },
93+ {
94+ "cell_type" : " markdown" ,
95+ "metadata" : {},
96+ "source" : [
97+ " ## Using a Specific Voice\n " ,
98+ " \n " ,
99+ " Use `reference_id` to specify a voice model from your Fish Audio account."
100+ ]
101+ },
102+ {
103+ "cell_type" : " code" ,
104+ "execution_count" : null ,
105+ "metadata" : {
106+ "ExecuteTime" : {
107+ "end_time" : " 2025-12-17T02:19:02.826568Z" ,
108+ "start_time" : " 2025-12-17T02:19:02.822894Z"
109+ }
110+ },
111+ "outputs" : [],
112+ "source" : [
113+ " # Replace with your voice model ID\n " ,
114+ " # audio = client.tts.convert(\n " ,
115+ " # text=\" Hello from a custom voice!\" ,\n " ,
116+ " # reference_id=\" your-voice-model-id\"\n " ,
117+ " # )\n " ,
118+ " # play(audio, notebook=True)"
119+ ]
120+ },
121+ {
122+ "cell_type" : " markdown" ,
123+ "metadata" : {},
124+ "source" : [
125+ " ## Streaming Audio\n " ,
126+ " \n " ,
127+ " For longer text, use `stream()` to process audio chunks as they arrive."
128+ ]
129+ },
130+ {
131+ "cell_type" : " code" ,
132+ "execution_count" : null ,
133+ "metadata" : {
134+ "ExecuteTime" : {
135+ "end_time" : " 2025-12-17T02:19:03.824681Z" ,
136+ "start_time" : " 2025-12-17T02:19:02.826991Z"
137+ }
138+ },
139+ "outputs" : [],
140+ "source" : [
141+ " stream = client.tts.stream(text=\" This is a longer piece of text that will be streamed.\" )\n " ,
142+ " audio = stream.collect()\n " ,
143+ " \n " ,
144+ " play(audio, notebook=True)"
145+ ]
146+ },
147+ {
148+ "cell_type" : " markdown" ,
149+ "metadata" : {},
150+ "source" : [
151+ " ## Check Account Credits"
152+ ]
153+ },
154+ {
155+ "cell_type" : " code" ,
156+ "execution_count" : null ,
157+ "metadata" : {
158+ "ExecuteTime" : {
159+ "end_time" : " 2025-12-17T02:19:03.897563Z" ,
160+ "start_time" : " 2025-12-17T02:19:03.833734Z"
161+ }
162+ },
163+ "outputs" : [],
164+ "source" : [
165+ " credits = client.account.get_credits()\n " ,
166+ " print(f\" Remaining credits: {credits.credit}\" )"
167+ ]
168+ }
169+ ],
170+ "metadata" : {
171+ "kernelspec" : {
172+ "display_name" : " Python 3" ,
173+ "language" : " python" ,
174+ "name" : " python3"
175+ },
176+ "language_info" : {
177+ "name" : " python" ,
178+ "version" : " 3.11.0"
179+ }
180+ },
181+ "nbformat" : 4 ,
182+ "nbformat_minor" : 4
183+ }
0 commit comments